coredump生成名与可执行文件名不一致原因分析

在Linux下,当进程因特定信号终止时,会生成coredump文件辅助调试。通常,coredump文件名包含执行文件名、PID等信息。然而,如果可执行文件名与生成的coredump文件名不一致,可能是由于设置了线程名导致的。本文通过测试代码展示了这种情况,并指出在gdb中加载core文件可以确认coredump的来源。总结了三点关键信息:coredump的默认命名、线程名对%e选项的影响及gdb中确认core来源的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

        众所周知,linux下进程当收到某些信号而终止时,会保存进程上下文信息进入coredump文件中;以帮助程序员们分析调试。它可以通过执行如下命令使能coredump生成。其生成路径定义在/proc/sys/kernel/core_pattern文件中,生成文件名格式定义在内核源码的Documentation/sysctl/kernel.txt。如下我定义生成文件名规则是%e_%P_%t_%s.core,%e是执行文件名(可能被截断),%P是pid,%t是coredump生成时间戳, %s是触发生成coredump的信号值。

ulimit -c unlimited
root@# cat /proc/sys/kernel/core_pattern 
/mnt/%e_%P_%t_%s.core
core_pattern:

core_pattern is used to specify a core dumpfile pattern name.
. max length 128 characters; default value is "core"
. core_pattern is used as a pattern template for the output filename;
  certain string patterns (beginning with '%') are substituted with
  their actual values.
. backward compatibility with core_uses_pid:
	If core_pattern does not include "%p" (default does not)
	and core_uses_pid is set, then .PID will be appended to
	the filename.
. corename format specifiers:
	%<NUL>	'%' is d
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值