对于多线程应用程序,如果能够给每个线程命名,那么调试起来的便利是不言而喻的。
可以用prctl给进程内其它线程命名的接口,测试代码如下:
|
makefile:
.PHONY: all
all: thread
thread : thread.cpp
g++ -ggdb -Wall -lpthread -o thread thread.cpp
clean:
rm -f thread *.swp
看thread进程,但是还看不到线程信息
beauty@linux-gznp:~/code/test> ps aux | grep thread | grep beauty | grep -v grep
beauty 8364 0.0 0.3 10872 904 pts/2 Sl 03:24 0:00 ./thread
再给ps加几个参数就ok了。
ps -L -p `ps aux | grep thread | grep $USER | grep -v grep | awk '{print $2}'`
PID LWP TTY TIME CMD
8364 8364 pts/2 00:00:00 thread
8364 8365 pts/2 00:00:00 xx
这里的-L,也可以使用-T,只是打出的详细信息有点儿不同。具体如下:
-L Show threads, possibly with LWP and NLWP columns
-T Show threads, possibly with SPID column
转自:http://www.cppblog.com/beautykingdom/archive/2009/11/08/100419.html
最后
以上就是紧张夕阳最近收集整理的关于用prctl给线程命名的全部内容,更多相关用prctl给线程命名内容请搜索靠谱客的其他文章。
发表评论 取消回复