linux下的core文件路径及文件名设置

方式一、临时设置 

1 、如何生成 coredump 文件 ?
 1)使用ulimit -c命令可查看core文件的生成开关。若结果为0,则表示关闭了此功能,不会生成core文件。
 2)使用ulimit -c filesize命令,可以限制core文件的大小(filesize的单位为kbyte),如果生成的信息超过此大小,将会被裁剪,最终生成一个不完整的core文件。在调试此core文 件的时候,gdb会提示错误。。若ulimit -c unlimited,则表示core文件的大小不受限制。
  
2、设置 Core Dump 的核心转储文件目录和命名规则
/proc/sys/kernel/core_uses_pid 可以控制产生的 core 文件的文件名中是否添加 pid 作为扩展 ,如果添加则文件内容为 1 ,否则为 0
proc/sys/kernel/core_pattern 可以设置格式化的 core 文件保存位置或文件名 ,比如原来文件内容是 core-%e
可以这样修改 :
echo "/corefile/core-%e-%p-%t" > core_pattern
将会控制所产生的 core 文件会存放到 /corefile 目录下,产生的文件名为 core- 命令名 -pid- 时间戳
以下是参数列表 :
    %p - insert pid into filename 添加 pid
    %u - insert current uid into filename 添加当前 uid
    %g - insert current gid into filename 添加当前 gid
    %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 添加命令名

方法二、永久设置

1、如何生成core文件

在/etc/profile中最后添加ulimit -c unlimited

2、命名规则及保存路径设置

在/etc目录中的sysctl.conf文件中最后添加如下内容:

kernel.core_pattern=/corefile/core.%e.%p.%t(生成的core文件需要放置的路径及文件命名格式)

在添加完成后保存并退出,使用source ./sysctl.conf执行sysctl.conf文件,使得设置立即生效

猜你喜欢

转载自blog.csdn.net/houxiaoliwang/article/details/79129032