Process groups
We have already established that every process has a unique process ID (pid). Every process also has a (possibly non-unique) process group ID (pgid) which, by default, is the same as the pgid of its parent process. Processes can get and set their process group ID with getpgid()
, setpgid()
, getpgrp()
, or setpgrp()
. See the man pages for more information.
Keep in mind that when your shell starts a new program, that program might require multiple processes to function correctly. All of these processes will inherit the same process group ID of the original process. So it may be a good idea to put each shell subprocess in its own process group to simplify your bookkeeping. When you move each subprocess into its own process group, the pgid should be equal to the pid.