OSDN Git Service

LDP: Update original to LDP v3.79
[linuxjm/LDP_man-pages.git] / original / man2 / setsid.2
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>
4 .\"
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.
10 .\"
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.
15 .\"
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.
20 .\"
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/>.
24 .\" %%%LICENSE_END
25 .\"
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>
30 .\"
31 .TH SETSID 2 2014-12-31 "Linux" "Linux Programmer's Manual"
32 .SH NAME
33 setsid \- creates a session and sets the process group ID
34 .SH SYNOPSIS
35 .ad l
36 .B #include <unistd.h>
37 .sp
38 .B pid_t setsid(void);
39 .br
40 .ad b
41 .SH DESCRIPTION
42 .BR setsid ()
43 creates a new session if the calling process is not a
44 process group leader.
45 The calling process is the leader of the new session
46 (i.e., its session ID is made the same as it process ID).
47 The calling process also becomes
48 the process group leader of a new process group in the session
49 (i.e., its process group ID is made the same as it process ID).
50
51 The calling process will be the only process in
52 the new process group and in the new session.
53 The new session has no controlling terminal.
54 .SH RETURN VALUE
55 On success, the (new) session ID of the calling process is returned.
56 On error,
57 .I "(pid_t)\ \-1"
58 is returned, and
59 .I errno
60 is set to indicate the error.
61 .SH ERRORS
62 .TP
63 .B EPERM
64 The process group ID of any process equals the PID of the calling process.
65 Thus, in particular,
66 .BR setsid ()
67 fails if the calling process is already a process group leader.
68 .SH CONFORMING TO
69 SVr4, POSIX.1-2001.
70 .SH NOTES
71 A child created via
72 .BR fork (2)
73 inherits its parent's session ID.
74 The session ID is preserved across an
75 .BR execve (2).
76
77 A process group leader is a process whose process group ID equals its PID.
78 Disallowing a process group leader from calling
79 .BR setsid ()
80 prevents the possibility that a process group leader places itself
81 in a new session while other processes in the process group remain
82 in the original session;
83 such a scenario would break the strict
84 two-level hierarchy of sessions and process groups.
85 In order to be sure that
86 .BR setsid ()
87 will succeed,
88 .BR fork (2)
89 and
90 .BR _exit (2),
91 and have the child do
92 .BR setsid ().
93 .SH SEE ALSO
94 .BR setsid (1),
95 .BR getsid (2),
96 .BR setpgid (2),
97 .BR setpgrp (2),
98 .BR tcgetsid (3),
99 .BR credentials (7)
100 .SH COLOPHON
101 This page is part of release 3.79 of the Linux
102 .I man-pages
103 project.
104 A description of the project,
105 information about reporting bugs,
106 and the latest version of this page,
107 can be found at
108 \%http://www.kernel.org/doc/man\-pages/.