Process Groups – Purpose of Abstractions, Session, Session Leader and Process Groups

job-controlprocess-groupssession

I understand from Informit article that sessions and process groups are used to terminate descendant processes on exit and send signals to related processes with job control.

I believe this information can be extracted at any point using the PPID of every process. Do these concepts exist in place just to have a data structure that enables getting descendants of a process quickly?

Do session and process groups get employed in things other than job control and termination of descendants? do they store any context information?

Any good references will be helpful.

Best Answer

Process groups exist primarily to determine which processes started from a terminal can access that terminal. Only processes in the foreground process group may read or write to their controlling terminal; background processes are stopped by a SIGTTIN or SIGTTOU signal.

You can send a signal atomically to all the processes in a process group, by passing a negative PID argument to kill. This also happens when a signal is generated by the terminal driver in response to a special character (e.g. SIGINT for Ctrl+C).

Sessions track which process groups are attached to a terminal. Only processes running in the same session as the controlling process are foreground or background processes.

It is not possible to determine process groups or sessions from the PPID. You would have no way to know whether the parent of a process is in the same process group or a different one, and likewise for sessions.