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 .\" SPDX-License-Identifier: GPL-2.0-or-later
7 .\" Modified Sun Sep 11 19:19:05 1994 <faith@cs.unc.edu>
8 .\" Modified Mon Mar 25 10:19:00 1996 <aeb@cwi.nl> (merged a few
9 .\" tiny changes from a man page by Charles Livingston).
10 .\" Modified Sun Jul 21 14:45:46 1996 <aeb@cwi.nl>
12 .TH SETSID 2 2021-03-22 "Linux" "Linux Programmer's Manual"
14 setsid \- creates a session and sets the process group ID
17 .RI ( libc ", " \-lc )
20 .B #include <unistd.h>
22 .B pid_t setsid(void);
26 creates a new session if the calling process is not a
28 The calling process is the leader of the new session
29 (i.e., its session ID is made the same as its process ID).
30 The calling process also becomes
31 the process group leader of a new process group in the session
32 (i.e., its process group ID is made the same as its process ID).
34 The calling process will be the only process in
35 the new process group and in the new session.
37 Initially, the new session has no controlling terminal.
38 For details of how a session acquires a controlling terminal, see
41 On success, the (new) session ID of the calling process is returned.
46 is set to indicate the error.
50 The process group ID of any process equals the PID of the calling process.
53 fails if the calling process is already a process group leader.
55 POSIX.1-2001, POSIX.1-2008, SVr4.
59 inherits its parent's session ID.
60 The session ID is preserved across an
63 A process group leader is a process whose process group ID equals its PID.
64 Disallowing a process group leader from calling
66 prevents the possibility that a process group leader places itself
67 in a new session while other processes in the process group remain
68 in the original session;
69 such a scenario would break the strict
70 two-level hierarchy of sessions and process groups.
71 In order to be sure that
77 while the child (which by definition can't be a process group leader) calls
80 If a session has a controlling terminal, and the
82 flag for that terminal is not set,
83 and a terminal hangup occurs, then the session leader is sent a
87 If a process that is a session leader terminates, then a
89 signal is sent to each process in the foreground
90 process group of the controlling terminal.