Using proccess specific APIs on threads
Gilad Ben-Yossef May 15th, 2008
A lot of POSIX API’s require a PID, or process ID, as a parameter. Sometime it is useful to use such an API on a thread, rather then a process.
Since Linux internally implements all processes and threads as tasks, one can use the Linux specific gettid(2) system call to get the “Thread ID” of a thread, which is really equal to a process PID, at least so much as to be useful as a parameter for a POSIX system call that requires a PID.
The use is Linux specific, non portable and it is not clear if it is a stable API or an undocumented coincidence. Use with care.
This post originally appeared in the Codefidence Technoblog