OSDN Git Service

6d76944e32cb7d96409e0f002b4330e41f97dc56
[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 .\"
4 .\" %%%LICENSE_START(GPLv2+_DOC_FULL)
5 .\" This is free documentation; you can redistribute it and/or
6 .\" modify it under the terms of the GNU General Public License as
7 .\" published by the Free Software Foundation; either version 2 of
8 .\" the License, or (at your option) any later version.
9 .\"
10 .\" The GNU General Public License's references to "object code"
11 .\" and "executables" are to be interpreted as the output of any
12 .\" document formatting or typesetting system, including
13 .\" intermediate and printed output.
14 .\"
15 .\" This manual is distributed in the hope that it will be useful,
16 .\" but WITHOUT ANY WARRANTY; without even the implied warranty of
17 .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 .\" GNU General Public License for more details.
19 .\"
20 .\" You should have received a copy of the GNU General Public
21 .\" License along with this manual; if not, see
22 .\" <http://www.gnu.org/licenses/>.
23 .\" %%%LICENSE_END
24 .\"
25 .\" Modified Sun Sep 11 19:19:05 1994 <faith@cs.unc.edu>
26 .\" Modified Mon Mar 25 10:19:00 1996 <aeb@cwi.nl> (merged a few
27 .\"     tiny changes from a man page by Charles Livingston).
28 .\" Modified Sun Jul 21 14:45:46 1996 <aeb@cwi.nl>
29 .\"
30 .TH SETSID 2 2013-02-11 "Linux" "Linux Programmer's Manual"
31 .SH NAME
32 setsid \- creates a session and sets the process group ID
33 .SH SYNOPSIS
34 .ad l
35 .B #include <unistd.h>
36 .sp
37 .B pid_t setsid(void);
38 .br
39 .ad b
40 .SH DESCRIPTION
41 .BR setsid ()
42 creates a new session if the calling process is not a
43 process group leader.
44 The calling process is the leader of the new
45 session, the process group leader of the new process group, and has no
46 controlling terminal.
47 The process group ID and session ID of the calling
48 process are set to the PID of the calling process.
49 The calling process will be the only process in
50 this new process group and in this new session.
51 .SH RETURN VALUE
52 On success, the (new) session ID of the calling process is returned.
53 On error,
54 .I "(pid_t)\ \-1"
55 is returned, and
56 .I errno
57 is set to indicate the error.
58 .SH ERRORS
59 .TP
60 .B EPERM
61 The process group ID of any process equals the PID of the calling process.
62 Thus, in particular,
63 .BR setsid ()
64 fails if the calling process is already a process group leader.
65 .SH CONFORMING TO
66 SVr4, POSIX.1-2001.
67 .SH NOTES
68 A child created via
69 .BR fork (2)
70 inherits its parent's session ID.
71 The session ID is preserved across an
72 .BR execve (2).
73
74 A process group leader is a process with process group ID equal
75 to its PID.
76 In order to be sure that
77 .BR setsid ()
78 will succeed,
79 .BR fork (2)
80 and
81 .BR _exit (2),
82 and have the child do
83 .BR setsid ().
84 .SH SEE ALSO
85 .BR setsid (1),
86 .BR getsid (2),
87 .BR setpgid (2),
88 .BR setpgrp (2),
89 .BR tcgetsid (3),
90 .BR credentials (7)
91 .SH COLOPHON
92 This page is part of release 3.67 of the Linux
93 .I man-pages
94 project.
95 A description of the project,
96 information about reporting bugs,
97 and the latest version of this page,
98 can be found at
99 \%http://www.kernel.org/doc/man\-pages/.