181 lines
4.6 KiB
HTML
181 lines
4.6 KiB
HTML
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML><HEAD><TITLE>Man page of SETSID</TITLE>
|
|
</HEAD><BODY>
|
|
<H1>SETSID</H1>
|
|
Section: Linux Programmer's Manual (2)<BR>Updated: 2017-09-15<BR><A HREF="#index">Index</A>
|
|
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
|
|
|
|
<A NAME="lbAB"> </A>
|
|
<H2>NAME</H2>
|
|
|
|
setsid - creates a session and sets the process group ID
|
|
<A NAME="lbAC"> </A>
|
|
<H2>SYNOPSIS</H2>
|
|
|
|
|
|
<B>#include <<A HREF="file:///usr/include/sys/types.h">sys/types.h</A>></B>
|
|
|
|
<BR>
|
|
|
|
<B>#include <<A HREF="file:///usr/include/unistd.h">unistd.h</A>></B>
|
|
|
|
<P>
|
|
|
|
<B>pid_t setsid(void);</B>
|
|
|
|
<BR>
|
|
|
|
|
|
<A NAME="lbAD"> </A>
|
|
<H2>DESCRIPTION</H2>
|
|
|
|
<B>setsid</B>()
|
|
|
|
creates a new session if the calling process is not a
|
|
process group leader.
|
|
The calling process is the leader of the new session
|
|
(i.e., its session ID is made the same as its process ID).
|
|
The calling process also becomes
|
|
the process group leader of a new process group in the session
|
|
(i.e., its process group ID is made the same as its process ID).
|
|
<P>
|
|
|
|
The calling process will be the only process in
|
|
the new process group and in the new session.
|
|
<P>
|
|
|
|
Initially, the new session has no controlling terminal.
|
|
For details of how a session acquires a controlling terminal, see
|
|
<B><A HREF="/cgi-bin/man/man2html?7+credentials">credentials</A></B>(7).
|
|
|
|
<A NAME="lbAE"> </A>
|
|
<H2>RETURN VALUE</H2>
|
|
|
|
On success, the (new) session ID of the calling process is returned.
|
|
On error,
|
|
<I>(pid_t) -1</I>
|
|
|
|
is returned, and
|
|
<I>errno</I>
|
|
|
|
is set to indicate the error.
|
|
<A NAME="lbAF"> </A>
|
|
<H2>ERRORS</H2>
|
|
|
|
<DL COMPACT>
|
|
<DT id="1"><B>EPERM</B>
|
|
|
|
<DD>
|
|
The process group ID of any process equals the PID of the calling process.
|
|
Thus, in particular,
|
|
<B>setsid</B>()
|
|
|
|
fails if the calling process is already a process group leader.
|
|
</DL>
|
|
<A NAME="lbAG"> </A>
|
|
<H2>CONFORMING TO</H2>
|
|
|
|
POSIX.1-2001, POSIX.1-2008, SVr4.
|
|
<A NAME="lbAH"> </A>
|
|
<H2>NOTES</H2>
|
|
|
|
A child created via
|
|
<B><A HREF="/cgi-bin/man/man2html?2+fork">fork</A></B>(2)
|
|
|
|
inherits its parent's session ID.
|
|
The session ID is preserved across an
|
|
<B><A HREF="/cgi-bin/man/man2html?2+execve">execve</A></B>(2).
|
|
|
|
<P>
|
|
|
|
A process group leader is a process whose process group ID equals its PID.
|
|
Disallowing a process group leader from calling
|
|
<B>setsid</B>()
|
|
|
|
prevents the possibility that a process group leader places itself
|
|
in a new session while other processes in the process group remain
|
|
in the original session;
|
|
such a scenario would break the strict
|
|
two-level hierarchy of sessions and process groups.
|
|
In order to be sure that
|
|
<B>setsid</B>()
|
|
|
|
will succeed, call
|
|
<B><A HREF="/cgi-bin/man/man2html?2+fork">fork</A></B>(2)
|
|
|
|
and have the parent
|
|
<B><A HREF="/cgi-bin/man/man2html?2+_exit">_exit</A></B>(2),
|
|
|
|
while the child (which by definition can't be a process group leader) calls
|
|
<B>setsid</B>().
|
|
|
|
<P>
|
|
|
|
If a session has a controlling terminal, and the
|
|
<B>CLOCAL</B>
|
|
|
|
flag for that terminal is not set,
|
|
and a terminal hangup occurs, then the session leader is sent a
|
|
<B>SIGHUP</B>
|
|
|
|
signal.
|
|
<P>
|
|
|
|
If a process that is a session leader terminates, then a
|
|
<B>SIGHUP</B>
|
|
|
|
signal is sent to each process in the foreground
|
|
process group of the controlling terminal.
|
|
<A NAME="lbAI"> </A>
|
|
<H2>SEE ALSO</H2>
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?1+setsid">setsid</A></B>(1),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+getsid">getsid</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+setpgid">setpgid</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+setpgrp">setpgrp</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+tcgetsid">tcgetsid</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?7+credentials">credentials</A></B>(7),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?7+sched">sched</A></B>(7)
|
|
|
|
<A NAME="lbAJ"> </A>
|
|
<H2>COLOPHON</H2>
|
|
|
|
This page is part of release 5.05 of the Linux
|
|
<I>man-pages</I>
|
|
|
|
project.
|
|
A description of the project,
|
|
information about reporting bugs,
|
|
and the latest version of this page,
|
|
can be found at
|
|
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
|
|
<P>
|
|
|
|
<HR>
|
|
<A NAME="index"> </A><H2>Index</H2>
|
|
<DL>
|
|
<DT id="2"><A HREF="#lbAB">NAME</A><DD>
|
|
<DT id="3"><A HREF="#lbAC">SYNOPSIS</A><DD>
|
|
<DT id="4"><A HREF="#lbAD">DESCRIPTION</A><DD>
|
|
<DT id="5"><A HREF="#lbAE">RETURN VALUE</A><DD>
|
|
<DT id="6"><A HREF="#lbAF">ERRORS</A><DD>
|
|
<DT id="7"><A HREF="#lbAG">CONFORMING TO</A><DD>
|
|
<DT id="8"><A HREF="#lbAH">NOTES</A><DD>
|
|
<DT id="9"><A HREF="#lbAI">SEE ALSO</A><DD>
|
|
<DT id="10"><A HREF="#lbAJ">COLOPHON</A><DD>
|
|
</DL>
|
|
<HR>
|
|
This document was created by
|
|
<A HREF="/cgi-bin/man/man2html">man2html</A>,
|
|
using the manual pages.<BR>
|
|
Time: 00:05:34 GMT, March 31, 2021
|
|
</BODY>
|
|
</HTML>
|