生成core文件的指定生成目录和文件名:

修改/etc/sysctl.conf添加一行:

kernel.core_pattern = /tmp/core-%e-%u-%s-%t-%h-%p

/sbin/sysctl –p 立即生效

则生成的core文件在/tmp目录,参数解释:

%e - insert coredumping executable name into filename 添加命令名

%u - insert current uid into filename 添加当前uid

%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 添加主机名

%p - insert pid into filename 添加pid

问题出在%e,导致core的程序名,如果名字很长的话,core文件中这一项会被截断为15个字符长度,通过查找资料:

The code for this can be found in exec.c here.

The code is going to copy the corename based on the pattern up to the first percentage (giving /cores/core.). At the percentage it's going to increment and process the 'e'. The code for processing the 'e' part prints out the pattern using snprintf based on the current->comm structure.

This is the executable name (excluding path) TRUNCATED to the value TASK_COMM_LEN. Since this is defined as 16 characters (at least in the Kernel I found) then SampleCrashApplication is truncated to 15 + 1 characters (1 for the null byte at the end) which explains why you get your truncated core dump name.

所以内核汇总有个宏 TASK_COMM_LEN限制了长度,经过验证:

vim include/linux/sched.h +162

c43a385aae432197a12dced6e2694ed0.png

果然有这个限制,所以在程序命名的时候尽量短一点,或者修改内核重新编译安装内核。

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐