- 查看core dump是否打开
ulimit -c
0为关闭 如果关闭可以使用ulimit -c unlimited打开
2 创建一个core输出目录 /corefile 将权限改为合适的权限,需要注意权限问题,不然core文件将无法写入
3 设置使用进程的pid为core文件的扩展名(可选项)
sysctl -w kernel.core_uses_pid=1 kernel.core_uses_pid=1
4.设置core的输出路径和输出名字
sysctl -w kernel.core_pattern=/corefile/core.%e.%p.%s.%E
这样就会生成/corefile/core.进程名.pid.信号值.文件路径 如下图
%字符对应的含义:
%p - insert pid into filename 添加pid(进程id)
%u - insert current uid into filename 添加当前uid(用户id)
%g - insert current gid into filename 添加当前gid(用户组id)
%s - insert signal that caused the coredump into the filename 添加导致产生core的信号
%t - insert UNIX time that the coredump occurred into filename 添加core文件生成时的unix时间
%h - insert hostname where the coredump happened into filename 添加主机名
%e - insert coredumping executable name into filename 添加导致产生core的命令名