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