The Linux Concept Journey — Process Group

Shlomi Boutnaru, Ph.D.
1 min readOct 2, 2023

--

Overall, a “Process Group” is a collection of processes which can be managed/handled together by the operating system (one example of that is signal management). Each “Process Group” has an identifier (PGID) and a “leader” which is the process that has created it. The PGID is equal to the PID of the group leader (https://biriukov.dev/docs/fd-pipe-session-terminal/3-process-groups-jobs-and-sessions/).

Moreover, we can use getpgid/getpgrp to get PGID or setpgid/setpgrp to set it (https://man7.org/linux/man-pages/man2/setpgid.2.html). The setgrp/getgrp is a System-V API which setpgid/getpgid is the POSIX API (https://unix.stackexchange.com/questions/404054/how-is-a-process-group-id-set). The POSIX one is the preferred one. Thus, if we check grep.app we can see that “setgpid” (https://grep.app/search?q=%20setpgid%28) has more than 29 times more results than “setpgrp” ( https://grep.app/search?q=%20setpgrp%28).

Lastly, any time we execute a command in a shell or a pipeline of commands we create a “Process Group” (it is sometimes called a job in the shell). As we can see in the screenshot below the number of the “Process Group” changes for each execution, and for the last one it gets incremented by one only even though we execute 5 processes (cause it is the same pipeline).

--

--