ptg10805159Section 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 proc4proc5process group process groupprocess groupsession
Figure 9.6Arrangement of processes into process groups and sessionsThe 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 formproc1 | proc2 &
proc3 | proc4 | proc5Aprocess establishes a new session by calling thesetsidfunction.
#include <unistd.h>
pid_t setsid(void);
Returns: process group ID if OK,−1 on errorIf 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.