1setsid(2) System Calls setsid(2)
2
3
4
6 setsid - create session and set process group ID
7
9 #include <sys/types.h>
10 #include <unistd.h>
11
12 pid_t setsid(void);
13
14
16 The setsid() function creates a new session, if the calling process is
17 not a process group leader. Upon return the calling process will be the
18 session leader of this new session, will be the process group leader of
19 a new process group, and will have no controlling terminal. The process
20 group ID of the calling process will be set equal to the process ID of
21 the calling process. The calling process will be the only process in
22 the new process group and the only process in the new session.
23
25 Upon successful completion, setsid() returns the value of the process
26 group ID of the calling process. Otherwise it returns (pid_t)−1 and
27 sets errno to indicate the error.
28
30 The setsid() function will fail if:
31
32 EPERM The calling process is already a process group leader, or the
33 process group ID of a process other than the calling process
34 matches the process ID of the calling process.
35
36
38 See attributes(5) for descriptions of the following attributes:
39
40
41
42
43 ┌─────────────────────────────┬─────────────────────────────┐
44 │ ATTRIBUTE TYPE │ ATTRIBUTE VALUE │
45 ├─────────────────────────────┼─────────────────────────────┤
46 │Interface Stability │Standard │
47 ├─────────────────────────────┼─────────────────────────────┤
48 │MT-Level │Async-Signal-Safe │
49 └─────────────────────────────┴─────────────────────────────┘
50
52 getsid(2), setpgid(2), setpgrp(2), attributes(5), standards(5)
53
55 A call to setsid() by a process that is a process group leader will
56 fail. A process can become a process group leader by being the last
57 member of a pipeline started by a job control shell. Thus, a process
58 that expects to be part of a pipeline, and that calls setsid(), should
59 always first fork; the parent should exit and the child should call
60 setsid(). This will ensure that the calling process will work reliably
61 when started by both job control shells and non-job control shells.
62
63
64
65SunOS 5.11 21 Aug 2002 setsid(2)