我有一个用 C/C++ 编写的多线程 Linux 应用程序。我有 chosen names for my threads .为了帮助调试,我希望这些名称在 GDB、“top”等中可见。这可能吗?如果可以,如何?
(有很多 reasons to know the thread name 。现在我想知道哪个线程占用了 50% 的 CPU(由 'top' 报告)。调试时我经常需要切换到不同的线程 - 目前我必须执行“thread apply all bt
”,然后查看回溯输出页面以找到正确的线程)。
Windows solution is here ; Linux 是什么?
最佳答案
Posix 线程?
这显然不会编译,但它会让你知道去哪里打猎。我什至不确定它是正确的 PR_
命令,但我认为它是正确的。好久不见……
#include <sys/prctl.h>
prctl(PR_SET_NAME,"<null> terminated string",0,0,0)
https://stackoverflow.com/questions/778085/
相关文章:
linux - 使用 linux 命令行 (bash) 从网络摄像头拍照
ruby-on-rails - 如何在 Linux 上使用 Ruby 2.0 改进 unicorn
linux - Vagrant 的鸡和蛋 : Shared folder with uid = ap
php - 如何在 Ubuntu 14.04 上更改 php-cli 版本?
linux - 在 PHP CLI 中设置 max_execution_time
linux - 我需要 -D_REENTRANT 和 -pthreads 吗?
linux - 如何在 AWS 上的 Amazon Linux AMI 中自动启动 node.js
ruby-on-rails - Ruby on Rails - 无法将 "\x89"从 ASCII-