验证环境:ubuntu 20.04
一、修改core文件路径
使用管理员模式,修改"/proc/sys/kernel/core_pattern"文件。
su
echo "core_%e_%p_%t" > /proc/sys/kernel/core_pattern
该路径为在执行文件当前路径创建相应的core文件,其中可选参数列表为:
%p - insert pid info filename
%u - insert current uid into filename
%g - insert current gid into filename
%s - insert signal that the coredump into the filename
%t - insert UNIX time that the coredump occurred into filename
%h - insert hostname where the coredump happened into filename
%e - insert coredumping executable name into filename
二、使能core文件生成
在ubuntu环境下,默认不生成core文件,需要生成core文件时,需要使用ulimit进行设定。
# 列出当前终端所有资源限制
ulimit -a
# 设置生成core文件的大小:1024k
ulimit -c 1024
# 设置生成core文件的大小:不受限制
ulimit -c unlimited
默认终端资源配置:
执行ulimit -c unlimited后终端资源配置:
注意:在终端通过ulimit命令设置core file size,仅在当前终端有效。
三、验证core文件生成
在修改core文件路径和开启core文件生成后,可以使用kill命令简单验证core文件生成。
kill -s SIGSEGV $$
四、遗留问题
- 基于ubuntu默认配置的core路径,无法查看到对应生成的core文件。