在CentOS或者suse等Linux系统中默认是关闭coredump核心转储的,也就不会产生core文件。由于在C/C++开发中会用到gdb调试,所以需要开启coredump功能。下面是具体的配置命令,可以保存为一个简单的shell脚本执行。
#!/bin/bash
### Filename: coredumpshell.sh
### Description: enable coredump and format the name of core file on centos system
# enable coredump whith unlimited file-size for all users
echo -e "\n# enable coredump whith unlimited file-size for all users\n* soft core unlimited" >> /etc/security/limits.conf
# set the path of core file with permission 777
cd /mydata && mkdir corefile && chmod 777 corefile
# format the name of core file.
# %% – 符号%
# %p – 进程号
# %u – 进程用户id
# %g – 进程用户组id
# %s – 生成core文件时收到的信号
# %t – 生成core文件的时间戳(seconds since 0:00

本文介绍如何在CentOS系统中开启core dump功能,并详细配置core文件的生成路径、名称格式,确保C/C++程序崩溃时能生成详细的core文件,便于后续gdb调试。
最低0.47元/天 解锁文章
838

被折叠的 条评论
为什么被折叠?



