Process Groups, Sessions, and Job Control 701Figure 34-1 shows the process group and session relationships between the various
processes resulting from the execution of the following commands:$ echo $$ Display the PID of the shell
400
$ find / 2> /dev/null | wc -l & Creates 2 processes in background group
[1] 659
$ sort < longlist | uniq -c Creates 2 processes in foreground groupAt this point, the shell (bash), find, wc, sort, and uniq are all running.Figure 34-1: Relationships between process groups, sessions, and the controlling terminal34.2 Process Groups
Each process has a numeric process group ID that defines the process group to
which it belongs. A new process inherits its parent’s process group ID. A process
can obtain its process group ID using getpgrp().PID = 400
PPID = 399bashPGID = 400PPID = 400findPGID = 658
SID = 400PID = 659
PPID = 400wcPGID = 658
SID = 400PPID = 400sortPGID = 660
SID = 400PID = 661
PPID = 400uniqPGID = 660
SID=400
Process
group 660Session 400session
leaderbackground
process groupsforeground
process groupcontrolling processprocess group leadersControlling terminal
Foreground PGID = 660
Controlling SID = 400SID = 400PID = 658 PID = 660Process
group 658Process
group 400#include <unistd.h>pid_t getpgrp(void);
Always successfully returns process group ID of calling process