In the Linux world, pid means two things. It’s the id of a process from POSIX’s point of view and the id of a task from kernel’s point of view.
In POSIX, process is an instance of a running program and it contains one or more threads. The id of a process is called pid.
In the Linux kernel, task is the basic execution unit and is thread in the POSIX definition. Task is represented by
struct task_struct in the code:
1 2 3 4 5 6
Here, pid is the id of a task and tgid is the id of the thread group that contains the task. As we can see,
task_struct.pid basically is POSIX thread id and
task_struct.tgid is POSIX process id.
Two different meanings of pid can cause lots of confusions and it’s important to know whether we are talking about pid in the POSIX context or in the Linux kernel context.
getpid() is a function defined by the POSIX standard and pid means the id of a process in this context. Linux implements it by returning
1 2 3
The proc file system is an interface to kernel data structures and pid means the id of a task/thread in this context. For example,
/proc/[pid]/status shows status information about the task/thread and the implementation is in