mxjijo
asked on
process id and pthread id
Hello there,
This must be a FAQ. I need to know how can I get the process id of the current pthread.
When I call pthread_self() it returns pthread_t value (integer), which is different from the pid
that I see on "ps" comamnd or gdb.
I need a way to either -
1) get the process id of a (current) pthread
OR
2) An easy way to relate process id to a pthread id from gdb.
thanks
pthread_self() returns the thread id not the process id. Call getpid() to fetch the id of the current process.
ASKER
>> Call getpid() to fetch the id of the current process
Yes, getpid() returns the process id. But it is the process id of the process itself.
Take a look at the output of command "ps -ef -L | grep my_proc"
root 17249 1 17249 0 15 May31 ? 00:00:00 my_proc
root 17249 1 17250 0 15 May31 ? 00:00:00 my_proc
root 17249 1 17252 0 15 May31 ? 00:00:00 my_proc
root 17249 1 17253 0 15 May31 ? 00:01:57 my_proc
my_proc has 4 threads in it.
Column 2 (17249) is the process id of the process. getpid() will return 17249, no matter from what thread you call it.
What I need is column 4. Those are the process ids of weight processes (pthreads) running inside the process 17249.
That is the LWP id. Try calling lwp_from_thread(). [I am not at a Linux box right now, so I don't know if that function is available to user-space apps.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks ravenpl that works.
I cannot call gettid() directly - not compiling but
syscall(NR__gettid) works great.
I cannot call gettid() directly - not compiling but
syscall(NR__gettid) works great.