1SETSID(2) Linux Programmer's Manual SETSID(2)
2
3
4
6 setsid - creates a session and sets the process group ID
7
9 #include <unistd.h>
10
11 pid_t setsid(void);
12
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 terminal. The process group ID and session ID of the calling
18 process are set to the PID of the calling process. The calling process
19 will be the only process in this new process group and in this new ses‐
20 sion.
21
23 On success, the (new) session ID of the calling process is returned.
24 On error, (pid_t) -1 is returned, and errno is set to indicate the
25 error.
26
28 EPERM The process group ID of any process equals the PID of the call‐
29 ing process. Thus, in particular, setsid() fails if the calling
30 process is already a process group leader.
31
33 SVr4, POSIX.1-2001.
34
36 A child created via fork(2) inherits its parent's session ID. The ses‐
37 sion ID is preserved across an execve(2).
38
39 A process group leader is a process with process group ID equal to its
40 PID. In order to be sure that setsid() will succeed, fork(2) and
41 _exit(2), and have the child do setsid().
42
44 setsid(1), getsid(2), setpgid(2), setpgrp(2), tcgetsid(3), creden‐
45 tials(7)
46
48 This page is part of release 3.53 of the Linux man-pages project. A
49 description of the project, and information about reporting bugs, can
50 be found at http://www.kernel.org/doc/man-pages/.
51
52
53
54Linux 2013-02-11 SETSID(2)