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 <unistd.h>
10
11       pid_t setsid(void);
12

DESCRIPTION

14       setsid()  creates a new session if the calling process is not a process
15       group leader.  The calling process is the leader of  the  new  session,
16       the  process group leader of the new process group, and has no control‐
17       ling tty.  The process group ID and session ID of the  calling  process
18       are set to the PID of the calling process.  The calling process will be
19       the only process in this new process group and in this new session.
20

RETURN VALUE

22       On success, the (new) session ID of the calling  process  is  returned.
23       On  error,  (pid_t) -1  is  returned,  and errno is set to indicate the
24       error.
25

ERRORS

27       EPERM. The process group ID of any process equals the PID of the  call‐
28              ing process.  Thus, in particular, setsid() fails if the calling
29              process is already a process group leader.
30

CONFORMING TO

32       SVr4, POSIX.1-2001.
33

NOTES

35       A child created via fork(2) inherits its parent's session ID.  The ses‐
36       sion ID is preserved across an execve(2).
37
38       A  process group leader is a process with process group ID equal to its
39       PID.  In order to be sure  that  setsid()  will  succeed,  fork(2)  and
40       _exit(2), and have the child do setsid().
41

SEE ALSO

43       getsid(2), setpgid(2), setpgrp(2), tcgetsid(3), credentials(7)
44

COLOPHON

46       This  page  is  part of release 3.22 of the Linux man-pages project.  A
47       description of the project, and information about reporting  bugs,  can
48       be found at http://www.kernel.org/doc/man-pages/.
49
50
51
52Linux                             2008-12-03                         SETSID(2)
Impressum