4

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.

1 Answer 1

6

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.

2
  • can i say that these concepts are applicable to only login and login shells and these concepts do not apply to daemon processes which do not have a controlling terminal? so the datastructure is more like, on a new terminal connection, session is created and the shell is the session leader. when each command (including/without pipe) is executed, process groups are created and attached to the session. There is only one process group in a session which is in foreground that can read/write to terminal.
    – rag
    Jul 15, 2013 at 7:49
  • @rag These concepts apply to processes that have a controlling terminal. It's not just login shells (and while login shells often do have a controlling terminal, it isn't always the case): any shell starting in a terminal such as screen or xterm is a session leader. For daemon processes, process groups and sessions aren't very useful (though process groups can be used to signal all the processes in a multi-process daemon atomically). Jul 15, 2013 at 8:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .