http://www.cnblogs.com/hugetong/p/6898608.html
一个程序挂掉了, 怎么办? 启动coredump
写一个脚本:
[root@T185 ~]# cat /etc/a.sh ulimit -c 204800 cd /data/coredump/ /root/a.out cd - [root@T185 ~]#
ulimit -c 的参数单位是512byte, 乘以204800就是100MB.
默认在那个目录启动, 就在那个目录存在coredump, 所以就cd一下.
当然配置参数也是可以的, 但是我不会. 大概就是下面这样干:
原文地址: http://www.cppblog.com/kongque/archive/2011/03/07/141262.aspx
3) 默认情况下,core dump生成的文件名为core,而且就在程序当前目录下。新的core会覆盖已存在的core。通过修改/proc/sys/kernel/core_uses_pid文件,可以将进程的pid作为作为扩展名,生成的core文件格式为core.xxx,其中xxx即为pid 4) 通过修改/proc/sys/kernel/core_pattern可以控制core文件保存位置和文件格式。例如:将所有的core文件生成到/corefile目录下,文件名的格式为core-命令名-pid-时间戳. echo "/corefile/core-%e-%p-%t" > /proc/sys/kernel/core_pattern
生成的core dump却不见了, 是为什么?
是这个服务删掉的: abrtd
[root@localhost ~]# cat /proc/sys/kernel/core_pattern
|/usr/libexec/abrt-hook-ccpp %s %c %p %u %g %t e
[root@localhost ~]# service abrtd status abrtd (pid 2950) is running... [root@localhost ~]# service abrtd stop Stopping abrt daemon: [ OK ]
[root@localhost ~]# tail -n 40 /var/log/messages |grep abrt Sep 28 15:21:37 localhost abrtd: Corrupted or bad directory /var/spool/abrt/ccpp-2017-09-28-15:21:23-12117, deleting Sep 28 15:26:03 localhost abrtd: Directory 'ccpp-2017-09-28-15:25:58-15980' creation detected Sep 28 15:26:03 localhost abrt[29435]: Saved core dump of pid 15980 (/opt/scorpion/KingKong/KingKong/KingKong) to /var/spool/abrt/ccpp-2017-09-28-15:25:58-15980 (1118617600 bytes) Sep 28 15:26:03 localhost abrtd: Executable '/opt/scorpion/KingKong/KingKong/KingKong' doesn't belong to any package Sep 28 15:26:03 localhost abrtd: 'post-create' on '/var/spool/abrt/ccpp-2017-09-28-15:25:58-15980' exited with 1 Sep 28 15:26:03 localhost abrtd: Corrupted or bad directory /var/spool/abrt/ccpp-2017-09-28-15:25:58-15980, deleting Sep 28 15:35:53 localhost abrtd: Got signal 15, exiting Sep 28 15:36:42 localhost abrt[19384]: abrtd is not running. If it crashed, /proc/sys/kernel/core_pattern contains a stale value, consider resetting it to 'core' Sep 28 15:36:42 localhost abrt[19384]: Saved core dump of pid 16325 to /data/coredump/core.16325 (209715200 bytes) [root@localhost ~]#
参考: https://ephrain.net/linux-abrt-%E7%94%A2%E7%94%9F%E7%9A%84-core-dump-%E4%B8%8D%E8%A6%8B%E4%BA%86%EF%BC%9F/