1、ulimit -c 判断是否开启转储
为0 则没有开启
2、ulimit -c unlimited 设置转储core大小没有限制
3、设置转储文件位置 echo "/var/core/%t-%e-%p-%c.core" > /proc/sys/kernel/core_pattern
4、测试程序cpu_test
int main(int argc, char **argv) { unsigned char * c = 0x00;
*c = 'c'; return ;
}
5、运行./cpu_test 发生段错误、生成了core文件
1521694447-cpu_test-77274-18446744073709551615.core
1521696041-cpu_test-18423-18446744073709551615.core
1521696511-cpu_test-26547-18446744073709551615.core
1521698483-cpu_test-43924-18446744073709551615.core
6、gdb分析core文件 gdb ./cpu_test /var/core/1521698483-cpu_test-43924-18446744073709551615.core
Reading symbols from ./cpu_test...done.
[New LWP 18689]
Core was generated by `./cpu_test'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0 0x000000000040075d in main (argc=1, argv=0x7ffebf1ceb18)
at /home/karllen/projects/cpu_test/main.cpp:4
4 *c = 'c';
(gdb)