0. 在Ubuntu系统中直接运行导致coredump的程序并没有生成core文件
- 如下所示, 执行时出现异常, 虽然提示进行core dump实际上并没有产生core文件, 此时就需要配置一下了;
$ gcc -g test.c
$ ./a.out
Floating point exception (core dumped)
$ ll
total 32
drwxrwxr-x 2 neo neo 4096 Jan 28 20:51 ./
drwxrwxr-x 4 neo neo 4096 Jan 28 20:50 ../
-rwxrwxr-x 1 neo neo 17016 Jan 28 20:51 a.out*
-rw-rw-r-- 1 neo neo 171 Jan 28 20:51 test.c
1. core dump
设置
1.1 设置core文件格式
- 在配置文件
/etc/sysctl.conf
中, 配置core文件的格式, 参数名称为: kernel.core_pattern
, 参考配置如下:
kernel.core_pattern=core.%p.%u.%s.%e.%t
- 查询配置是否成功
sysctl -p
, 输出示例如下 :
$ sudo sysctl -p
[sudo] password for neo:
kernel.core_pattern = core.%p.%u.%s.%e.%t
1.2 设置core 大小限制
- 在配置文件
/etc/security/limits.conf
中, 配置core文件大小限制, 参考配置如下:
* soft core unlimited
* hard core unlimited
2. 写个代码测一下
2.1 示例代码放入 test.c
中
int actual_calc(int a, int b){
int c;
c=a