1 .\" Copyright Michael Haardt (michael@cantor.informatik.rwth-aachen.de)
2 .\" Sat Aug 27 20:43:50 MET DST 1994
3 .\" and Copyright (C) 2014, Michael Kerrisk <mtk.manpages@gmail.com>
5 .\" %%%LICENSE_START(GPLv2+_DOC_FULL)
6 .\" This is free documentation; you can redistribute it and/or
7 .\" modify it under the terms of the GNU General Public License as
8 .\" published by the Free Software Foundation; either version 2 of
9 .\" the License, or (at your option) any later version.
11 .\" The GNU General Public License's references to "object code"
12 .\" and "executables" are to be interpreted as the output of any
13 .\" document formatting or typesetting system, including
14 .\" intermediate and printed output.
16 .\" This manual is distributed in the hope that it will be useful,
17 .\" but WITHOUT ANY WARRANTY; without even the implied warranty of
18 .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 .\" GNU General Public License for more details.
21 .\" You should have received a copy of the GNU General Public
22 .\" License along with this manual; if not, see
23 .\" <http://www.gnu.org/licenses/>.
26 .\" Modified Sun Sep 11 19:19:05 1994 <faith@cs.unc.edu>
27 .\" Modified Mon Mar 25 10:19:00 1996 <aeb@cwi.nl> (merged a few
28 .\" tiny changes from a man page by Charles Livingston).
29 .\" Modified Sun Jul 21 14:45:46 1996 <aeb@cwi.nl>
31 .TH SETSID 2 2021-03-22 "Linux" "Linux Programmer's Manual"
33 setsid \- creates a session and sets the process group ID
37 .B #include <unistd.h>
39 .B pid_t setsid(void);
44 creates a new session if the calling process is not a
46 The calling process is the leader of the new session
47 (i.e., its session ID is made the same as its process ID).
48 The calling process also becomes
49 the process group leader of a new process group in the session
50 (i.e., its process group ID is made the same as its process ID).
52 The calling process will be the only process in
53 the new process group and in the new session.
55 Initially, the new session has no controlling terminal.
56 For details of how a session acquires a controlling terminal, see
59 On success, the (new) session ID of the calling process is returned.
64 is set to indicate the error.
68 The process group ID of any process equals the PID of the calling process.
71 fails if the calling process is already a process group leader.
73 POSIX.1-2001, POSIX.1-2008, SVr4.
77 inherits its parent's session ID.
78 The session ID is preserved across an
81 A process group leader is a process whose process group ID equals its PID.
82 Disallowing a process group leader from calling
84 prevents the possibility that a process group leader places itself
85 in a new session while other processes in the process group remain
86 in the original session;
87 such a scenario would break the strict
88 two-level hierarchy of sessions and process groups.
89 In order to be sure that
95 while the child (which by definition can't be a process group leader) calls
98 If a session has a controlling terminal, and the
100 flag for that terminal is not set,
101 and a terminal hangup occurs, then the session leader is sent a
105 If a process that is a session leader terminates, then a
107 signal is sent to each process in the foreground
108 process group of the controlling terminal.