1SETSID(2)                  Linux Programmer's Manual                 SETSID(2)
2
3
4

NAME

6       setsid - creates a session and sets the process group ID
7

SYNOPSIS

9       #include <sys/types.h>
10       #include <unistd.h>
11
12       pid_t setsid(void);
13

DESCRIPTION

15       setsid()  creates a new session if the calling process is not a process
16       group leader.  The calling process is the leader  of  the  new  session
17       (i.e., its session ID is made the same as its process ID).  The calling
18       process also becomes the process group leader of a new process group in
19       the session (i.e., its process group ID is made the same as its process
20       ID).
21
22       The calling process will be the only process in the new  process  group
23       and in the new session.
24
25       Initially, the new session has no controlling terminal.  For details of
26       how a session acquires a controlling terminal, see credentials(7).
27

RETURN VALUE

29       On success, the (new) session ID of the calling  process  is  returned.
30       On  error,  (pid_t) -1  is  returned,  and errno is set to indicate the
31       error.
32

ERRORS

34       EPERM  The process group ID of any process equals the PID of the  call‐
35              ing process.  Thus, in particular, setsid() fails if the calling
36              process is already a process group leader.
37

CONFORMING TO

39       POSIX.1-2001, POSIX.1-2008, SVr4.
40

NOTES

42       A child created via fork(2) inherits its parent's session ID.  The ses‐
43       sion ID is preserved across an execve(2).
44
45       A  process  group leader is a process whose process group ID equals its
46       PID.  Disallowing a process group leader from calling setsid() prevents
47       the possibility that a process group leader places itself in a new ses‐
48       sion while other processes in the process group remain in the  original
49       session;  such a scenario would break the strict two-level hierarchy of
50       sessions and process groups.  In order to be sure  that  setsid()  will
51       succeed,  call  fork(2)  and  have the parent _exit(2), while the child
52       (which by definition can't be a process group leader) calls setsid().
53
54       If a session has a controlling terminal, and the CLOCAL flag  for  that
55       terminal  is  not  set,  and a terminal hangup occurs, then the session
56       leader is sent a SIGHUP signal.
57
58       If a process that is a session leader terminates, then a SIGHUP  signal
59       is sent to each process in the foreground process group of the control‐
60       ling terminal.
61

SEE ALSO

63       setsid(1),  getsid(2),  setpgid(2),  setpgrp(2),  tcgetsid(3),  creden‐
64       tials(7), sched(7)
65

COLOPHON

67       This  page  is  part of release 5.07 of the Linux man-pages project.  A
68       description of the project, information about reporting bugs,  and  the
69       latest     version     of     this    page,    can    be    found    at
70       https://www.kernel.org/doc/man-pages/.
71
72
73
74Linux                             2017-09-15                         SETSID(2)
Impressum