linux core文件名长度,linux 生成的core文件名被截断问题分析

生成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

6961874df0f1f9cad3392bfcf37e9e94.png

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值