Skip to content

linux core dump配置

linux下core dump配置命令

1. 查看core dump状态

ulimit -c

若结果为0,则表示关闭了core dump输出,不会生成core dump文件。

2. 开启core dump输出

ulimit -c filesize

指定dump文件的最大大小(单位:KB),如果生成的dump文件超过此大小,将会被裁剪,最终生成一个不完整的dump文件。在调试此dump文件的时候,gdb会提示错误。

ulimit -c unlimited,dump文件的大小不受限制。

3. 设置core dump文件的名称和路径

core dump文件默认在当前路径下生成,文件名默认为core,若core dump文件已存在,会直接覆盖。

echo "1" > /proc/sys/kernel/core_uses_pid,控制core dump文件的文件名中是否添加pid作为扩展。

echo "/corefile/core-%e-%p-%t" > /proc/sys/kernel/core_pattern,设置core dump文件保存位置和文件名格式,以下是参数列表:

  • %p - insert pid into filename
  • %u - insert current uid into filename
  • %g - insert current gid into filename
  • %s - insert signal that caused the coredump into the filename
  • %t - insert UNIX time that the coredump occurred into filename
  • %h - insert hostname where the coredump happened into filename
  • %e - insert coredumping executable name into filename

core dump处理脚本,参考https://man7.org/linux/man-pages/man5/core.5.html

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.

/proc⽬录会在系统重启后动态⽣成,可以在/etc/sysctl.conf中配置core_pattern使其永久生效