ptg10805159
Section 9.5 Sessions 295
9.5 Sessions
Asession is a collection of one or moreprocess groups. For example, we could have the
arrangement shown in Figure9.6. Here we have three process groups in a single
session.
login shell proc1 proc2 proc3 proc4
proc5
process group process group
process group
session
Figure 9.6Arrangement of processes into process groups and sessions
The processes in a process group areusually placed there by a shell pipeline. For
example, the arrangement shown in Figure9.6 could have been generated by shell
commands of the form
proc1 | proc2 &
proc3 | proc4 | proc5
Aprocess establishes a new session by calling thesetsidfunction.
#include <unistd.h>
pid_t setsid(void);
Returns: process group ID if OK,−1 on error
If the calling process is not a process group leader,this function creates a new session.
Three things happen.
- The process becomes thesession leaderof this new session. (A session leader is
the process that creates a session.) The process is the only process in this new
session. - The process becomes the process group leader of a new process group. The new
process group ID is the process ID of the calling process. - The process has no controlling terminal. (We’ll discuss controlling terminals in
the next section.) If the process had a controlling terminal beforecalling
setsid,that association is broken.