[opensuse-programming] Get LWP of thread in openSUSE 11.2
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? -- Roger Oberholtzer OPQ Systems / Ramböll RST Ramböll Sverige AB Krukmakargatan 21 P.O. Box 17009 SE-104 62 Stockholm, Sweden Office: Int +46 10-615 60 20 Mobile: Int +46 70-815 1696 -- To unsubscribe, e-mail: opensuse-programming+unsubscribe@opensuse.org For additional commands, e-mail: opensuse-programming+help@opensuse.org
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 -- To unsubscribe, e-mail: opensuse-programming+unsubscribe@opensuse.org For additional commands, e-mail: opensuse-programming+help@opensuse.org
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 OPQ Systems / Ramböll RST Ramböll Sverige AB Krukmakargatan 21 P.O. Box 17009 SE-104 62 Stockholm, Sweden Office: Int +46 10-615 60 20 Mobile: Int +46 70-815 1696 -- To unsubscribe, e-mail: opensuse-programming+unsubscribe@opensuse.org For additional commands, e-mail: opensuse-programming+help@opensuse.org
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 -- To unsubscribe, e-mail: opensuse-programming+unsubscribe@opensuse.org For additional commands, e-mail: opensuse-programming+help@opensuse.org
participants (3)
-
Anders Johansson
-
Per Jessen
-
Roger Oberholtzer