1SETSID(3P) POSIX Programmer's Manual SETSID(3P)
2
3
4
6 This manual page is part of the POSIX Programmer's Manual. The Linux
7 implementation of this interface may differ (consult the corresponding
8 Linux manual page for details of Linux behavior), or the interface may
9 not be implemented on Linux.
10
12 setsid — create session and set process group ID
13
15 #include <unistd.h>
16
17 pid_t setsid(void);
18
20 The setsid() function shall create a new session, if the calling
21 process is not a process group leader. Upon return the calling process
22 shall be the session leader of this new session, shall be the process
23 group leader of a new process group, and shall have no controlling ter‐
24 minal. The process group ID of the calling process shall be set equal
25 to the process ID of the calling process. The calling process shall be
26 the only process in the new process group and the only process in the
27 new session.
28
30 Upon successful completion, setsid() shall return the value of the new
31 process group ID of the calling process. Otherwise, it shall return -1
32 and set errno to indicate the error.
33
35 The setsid() function shall fail if:
36
37 EPERM The calling process is already a process group leader, or the
38 process group ID of a process other than the calling process
39 matches the process ID of the calling process.
40
41 The following sections are informative.
42
44 None.
45
47 None.
48
50 The setsid() function is similar to the setpgrp() function of System V.
51 System V, without job control, groups processes into process groups and
52 creates new process groups via setpgrp(); only one process group may be
53 part of a login session.
54
55 Job control allows multiple process groups within a login session. In
56 order to limit job control actions so that they can only affect pro‐
57 cesses in the same login session, this volume of POSIX.1‐2017 adds the
58 concept of a session that is created via setsid(). The setsid() func‐
59 tion also creates the initial process group contained in the session.
60 Additional process groups can be created via the setpgid() function. A
61 System V process group would correspond to a POSIX System Interfaces
62 session containing a single POSIX process group. Note that this func‐
63 tion requires that the calling process not be a process group leader.
64 The usual way to ensure this is true is to create a new process with
65 fork() and have it call setsid(). The fork() function guarantees that
66 the process ID of the new process does not match any existing process
67 group ID.
68
70 None.
71
73 getsid(), setpgid(), setpgrp()
74
75 The Base Definitions volume of POSIX.1‐2017, <sys_types.h>, <unistd.h>
76
78 Portions of this text are reprinted and reproduced in electronic form
79 from IEEE Std 1003.1-2017, Standard for Information Technology -- Por‐
80 table Operating System Interface (POSIX), The Open Group Base Specifi‐
81 cations Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of
82 Electrical and Electronics Engineers, Inc and The Open Group. In the
83 event of any discrepancy between this version and the original IEEE and
84 The Open Group Standard, the original IEEE and The Open Group Standard
85 is the referee document. The original Standard can be obtained online
86 at http://www.opengroup.org/unix/online.html .
87
88 Any typographical or formatting errors that appear in this page are
89 most likely to have been introduced during the conversion of the source
90 files to man page format. To report such errors, see https://www.ker‐
91 nel.org/doc/man-pages/reporting_bugs.html .
92
93
94
95IEEE/The Open Group 2017 SETSID(3P)