核心转储文件名使用core_pattern%e。%p.core获取线程名而不是可执行文件名 [英] core dump filename gets thread name instead of executable name with core_pattern %e.%p.core

查看:668
本文介绍了核心转储文件名使用core_pattern%e。%p.core获取线程名而不是可执行文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近开始使用pthread_setname_np()在应用程序中设置一些线程名称。执行完此操作后,如果在指定的线程之一中发生崩溃,则核心转储文件名将获取线程名,而不是具有core_pattern%e。%p.core

I recently started setting some thread names within my application by using pthread_setname_np(). After doing this, if a crash occurs within one of the named threads, the core dump filename is getting the thread name instead of executable name with core_pattern %e.%p.core

根据核心手册页,%e标志应该在core_pattern中将其扩展为可执行文件名称。它没有说任何有关线程名称的信息。

According to the core man page, the %e flag in the core_pattern is supposed to get expanded to the executable name. It doesn't say anything about the thread name.

我想要的是可执行文件的名称,而不是线程的名称,因为我还有其他的自动化脚本(不是我自己维护的)

I want the executable name and not the thread name, because I have other automated scripts (not maintained by me) that depend on the core filenames beginning with the application name.

这是pthread_setname_np()或core_pattern中的错误吗?

Is this a bug in pthread_setname_np() or core_pattern?

我正在Linux CentOS 6.7上运行。

I am running on Linux CentOS 6.7.

推荐答案

可以使用gdb检索生成内核的可执行文件名称。
以下显示它:

The executable name that generated the core can be retrieved by using gdb. The following prints it:

gdb -batch -ex "core corefile" | grep "Core was generated" | cut -d\` -f2 | cut -d"'" -f1 | awk '{print $1}'

或者更好的方法是使用pid%p和/ proc获得它。示例:

Or better yet use the pid %p and /proc to get it. Example:

$ sleep 900 &
[1] 2615
$ readlink /proc/$(pidof sleep)/exe
/bin/sleep
$ basename $(readlink /proc/$(pidof sleep)/exe)
sleep

这篇关于核心转储文件名使用core_pattern%e。%p.core获取线程名而不是可执行文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆