1. 设置core文件路径在当前工作目录
echo "core-%e-%p-%t" > /proc/sys/kernel/core_pattern
具体参数
%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的命令
%p - insert pid into filename 添加pid
%u - insert current uid into filename 添加uid
%g - insert current gid into filename 添加gid
2. 查看core文件设置大小限制
ulimit -c
3. 设置core文件大小
ulimit -c filesize
exp:
ulimit -c 100M
ulimit -c unlimited
gdb调试指令
编译一个测试程序
#include<stdio.h>
int coredump_next()
{
int *ptr = NULL;
*ptr = 101;
return 0;
}
int coredump(){
return coredump_next();
}
int main()
{
return coredump();
}