tracing pthreads in linux?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7698209/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
tracing pthreads in linux?
提问by Sergey
I did not find any tool created for tracing pthread's threads in linux process. I want something like strace/ltrace, is there something to view calls in real-time? Thank you
I did not find any tool created for tracing pthread's threads in linux process. I want something like strace/ltrace, is there something to view calls in real-time? Thank you
采纳答案by nos
strace works for threads as well. Use strace -f
to strace all threads.
strace works for threads as well. Use strace -f
to strace all threads.
To strace only a particular thread, you first have to find its tid (thread id). Threads have thread id's that's really a pid (process id)
To strace only a particular thread, you first have to find its tid (thread id). Threads have thread id's that's really a pid (process id)
Once you know the pid of the thread, use strace -p the_pid
to strace that thread.
Once you know the pid of the thread, use strace -p the_pid
to strace that thread.
The pids of all the threads in a process can be found in /proc/<pid>/task/
, or the current thread id can be learned with the gettid()
C call.
The pids of all the threads in a process can be found in /proc/<pid>/task/
, or the current thread id can be learned with the gettid()
C call.
回答by jiayy
actually strace is not as good as perf .
actually strace is not as good as perf .
use perf tool , you can get more information.
use perf tool , you can get more information.
for example, if some of your threads hangs , and you want to find out what functions calls that hangs, use strace -p pid-id returns limited information, but perf top , or perf -t tid returns more
for example, if some of your threads hangs , and you want to find out what functions calls that hangs, use strace -p pid-id returns limited information, but perf top , or perf -t tid returns more