The Linux process has a certain relationship with each other. For example, in the Linux process Foundation, we see that each process has a parent process, and all processes take the init process as the root, forming a tree structure. Here we explain the process groups and sessions in order to manage the process in a richer way.
1. Group of processes (process group)
Each process belongs to a process group, and each process group can contain multiple processes. The process group will have a process group leadership process (processes group leader), and the leader process's PID (the PID sees the Linux process base) becomes the process group ID (processes group ID, pgid) to identify the process group.
$ps-O Pid,pgid,ppid,comm | Cat
PID Pgid PPID COMMAND
17763 17763 17751 Bash
18534 18534 17763 PS
18535 18534 17763 Cat
The PID is the id,pgid of the process itself as the ID of the process group in which the process is located, ppid the process's parent process ID. From the results above, we can extrapolate the following relationship:
The arrows in the diagram indicate that the parent process produces a subprocess through the fork and exec mechanisms. Both PS and cat are child processes of bash. The PID of the process group's lead process becomes the process group ID. The leadership process can be terminated first. The process group still exists and holds the same pgid until the last process in the process group is terminated.
One of the important reasons why we classify processes as process groups is that we can send signals to a process group. All processes in the process group will receive the signal. We will discuss this in depth in the next section.