【发布时间】:2010-10-21 03:44:01
【问题描述】:
我有一个用 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 是什么?
【问题讨论】:
-
不知何故
prctl()(和pthread_setname_np()对我不起作用。它改变了我所有线程的名称。所以相当没用。相反我不得不将名称写入 comm 文件。见:stackoverflow.com/questions/68676407/…
标签: c++ c linux multithreading