设置Core Dump的目录和命名规则

coredump文件的命名规则与内核中core_uses_pid和core_pattern有关

1、/proc/sys/kernel/core_uses_pid可以控制产生的core文件的文件名中是否添加pid作为扩展,如果添加则文件内容为1,否则为0
/proc/sys/kernel/core_pattern可以设置格式化的core文件保存位置或文件名,比如原来文件内容是core-%e
可以这样修改:
echo "/corefile/core-%e-%p-%t" > /proc/sys/kernel/core_pattern
将会控制所产生的core文件会存放到/corefile目录下,产生的文件名为core-命令名-pid-时间戳

2、/proc/sys/kernel/core_uses_pid

如果这个文件的内容被配置成1,那么即使core_pattern中没有设置%p,最后生成的core dump文件名仍会加上进程ID。

注意linux的内核参数信息都存在内存中,因此可以用过命令直接修改,并直接生效。但是当系统reboot后,之前设置的参数值就会丢失,而系统每次启动时都会去/etc/sysctl.conf文件中读取内核参数。

因此可以将参数写在这个配置文件中,如:

kernel.core_pattern = %e.core.%p

并保存退出,执行下面指令使其生效

sysctl -p


以下是摘自linux-2.6.32.59\Documentation\sysctl\kernel.txt

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
  %u  uid
  %g  gid
  %s  signal number
  %t  UNIX time of dump
  %h  hostname
  %e  executable filename
  %<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.
========================================================================
core_uses_pid:
The default coredump filename is "core".  By setting 
core_uses_pid to 1, the coredump filename becomes core.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.

你可能感兴趣的:(linux,coredump)