I have been investigating this and can't seem to find a solution.
I have a many threaded app that starts threads with pthread_create. I can see them in "ps -eLf", and I can strace each individual thread.
UID PID PPID LWP C NLWP STIME TTY TIME CMD roger 27912 22887 27912 93 12 13:45 pts/1 00:03:29 hiway roger 27912 22887 28372 0 12 13:45 pts/1 00:00:00 hiway roger 27912 22887 28373 0 12 13:45 pts/1 00:00:00 hiway roger 27912 22887 28374 0 12 13:45 pts/1 00:00:00 hiway roger 27912 22887 28375 0 12 13:45 pts/1 00:00:00 hiway roger 27912 22887 28376 0 12 13:45 pts/1 00:00:00 hiway roger 27912 22887 28377 0 12 13:45 pts/1 00:00:00 hiway roger 27912 22887 28378 0 12 13:45 pts/1 00:00:00 hiway roger 27912 22887 28379 0 12 13:45 pts/1 00:00:00 hiway roger 27912 22887 28380 0 12 13:45 pts/1 00:00:00 hiway roger 27912 22887 28381 0 12 13:45 pts/1 00:00:00 hiway roger 27912 22887 28382 84 12 13:45 pts/1 00:03:06 hiway
What I cannot do is have the thread list it's process id (LWP in the list above). getpid() returns the pid of the initial process that started the thread, as is in the PID column.
How can I get the value in the LWP column in the running thread itself?
On Friday 17 September 2010 14:19:21 Roger Oberholtzer wrote:
How can I get the value in the LWP column in the running thread itself?
gettid(2)
Anders
On Fri, 2010-09-17 at 14:51 +0200, Anders Johansson wrote:
On Friday 17 September 2010 14:19:21 Roger Oberholtzer wrote:
How can I get the value in the LWP column in the running thread itself?
gettid(2)
That did it. And Per's note about syscall was also useful. Should be a reference in the getpid/getppid man pages to call attention to this function. I tried names I thought it might be. gettid must have been too obvious. I expected something like racoonID() or some less than obvious call :)
Roger Oberholtzer wrote:
How can I get the value in the LWP column in the running thread itself?
http://linux.die.net/man/2/gettid
(not available in libc, you have to use syscall).
/Per Jessen, Zürich
programming@lists.opensuse.org