Linux内核源码 Documentation/sysctl/kernel.txt core_pattern:
core_pattern:
core_pattern is used to specify a core dumpfile pattern name.
. max length 128 characters; default value is "core"
. core_pattern is used as a pattern template for the output filename;
certain string patterns (beginning with '%') are substituted with
their actual values.
. backward compatibility with core_uses_pid:
If core_pattern does not include "%p" (default does not)
and core_uses_pid is set, then .PID will be appended to
the filename.
. corename format specifiers:
%<NUL> '%' is dropped
%% output one '%'
%p pid
%P global pid (init PID namespace)
%i tid
%I global tid (init PID namespace)
%u uid
%g gid
%d dump mode, matches PR_SET_DUMPABLE and
/proc/sys/fs/suid_dumpable
%s signal number
%t UNIX time of dump
%h hostname
%e executable filename (may be shortened)
%E executable path
%<OTHER> both are dropped
. If the first character of the pattern is a '|', the kernel will treat
the rest of the pattern as a command to run. The core dump will be
written to the standard input of that program instead of to a file.
脚本
#!bin/bash
#/proc/<pid>/maps
cat /proc/$1/maps > /tmp/maps_of_$1
#/proc/<pid>/smaps
cat /proc/$1/smaps > /tmp/smaps_of_$1
#coredump
dd > /tmp/core_$1_$2_$3
#gzip
gzip > /tmp/core_$1_$2_$3
ulimit -c unlimited echo "|/usr/local/coredump.sh %p %e %s" > /proc/sys/kernel/core_pattern
参考资料:
https://www.cnblogs.com/justin-y-lin/p/11327224.html
https://www.cnblogs.com/arnoldlu/p/11160510.html
http://www.brendangregg.com/blog/2016-08-09/gdb-example-ncurses.html