tid: (seeman 2 gettid) task idpid: process id (returned bygetpid())ppid: parent pid (getppid())pgid: return process group id (getpgid(_))
pid could be confusing in a multi-threaded program in Linux (NPTL). multiple threads can share the same pid.
The kernel, however, views them as tid, since NPTL is implemented in user space, the kernel doesn’t really know
much about NPTL threads, but threads created (clone with CLONE_THREAD flag) in the same process share the same
pid.
Their relations seems to be:
For reguar processes (not threads):
tid==pid
For threads:
- each thread has their own
tid(tidis also unique, but same aspid, they do wraps, seecat /proc/sys/kernel/pid_max). - threads created in the same process, share the same
pid.
To demostrate the problem, we can first do a fork, and then create threads (pthread_create) in both parent and child process.
The result shows:
- threads group 1 (parent): all threads have different
tid, share the samepidas parent,ppid=parent.ppid,pgid=parent - threads group 2 (child): all threads have different
tid, share the samepidas child,ppid=parent,pgid=parent
So even though the pgid are indeed the same for all threads created above, it is the pid from above should be used to identify their
relationship with the parent. This can be revealed by check /proc/pid/task/tid, i.e.: The tid can be discovered under /proc/pid.
Example source code can be found in (gist) Link