如何命名在Linux下一个线程? [英] How to name a thread in Linux?

查看:249
本文介绍了如何命名在Linux下一个线程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经写在C / C多线程的Linux应用程序++。我有选择的名称为我的线程的。为了帮助调试,我想这些名字在GDB可见,顶,等等。这是可能的,如果又如何?

I have a multithreaded Linux application written in C/C++. I have chosen names for my threads. To aid debugging, I would like these names to be visible in GDB, "top", etc. Is this possible, and if so how?

(有很多理由知道线程名。现在我想知道哪个线程占用了50%的CPU(如'顶'报道)和调试时,我经常需要切换到一个不同的线程 - 现在我要做的线程应用所有BT ,那么期待通过回溯输出的页面找到合适的线程)。

(There are plenty of reasons to know the thread name. Right now I want to know which thread is taking up 50% CPU (as reported by 'top'). And when debugging I often need to switch to a different thread - currently I have to do "thread apply all bt" then look through pages of backtrace output to find the right thread).

借助的Windows解决方案是这里;什么是Linux的一个?

The Windows solution is here; what's the Linux one?

推荐答案

Posix线程?

这显然不会编译,但它会给你哪里去打猎的想法。我甚至不知道它的正确 PR _ 命令,但我认为这是。这是一段时间...

This evidently won't compile, but it will give you an idea of where to go hunting. I'm not even sure its the right PR_ command, but i think it is. It's been a while...

  #include <sys/prctl.h>
  prctl(PR_SET_NAME,"<null> terminated string",0,0,0)

这篇关于如何命名在Linux下一个线程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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