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