11

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

2 Answers 2

18

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)

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.

2
  • wow thank you very much, i see strace's help hundred times but did not think that 'follow forks' will show threads
    – Sergey
    Oct 8, 2011 at 16:49
  • 1
    This does not work (for me, anyway). To be more specific, I'm using strace -f -p <pid> to attach the the thread I want to watch. Whenever it accepts a new socket connection it creates a pthread to handle it, but strace doesn't follow the pthread_create call into the new thread at all.
    – Michael
    Apr 4, 2012 at 21:09
2

actually strace is not as good as perf .

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.