Files
oldlinux-files/Ref-docs/POSIX/susv3/functions/setsid.html
2024-02-19 00:21:47 -05:00

148 lines
5.8 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta name="generator" content="HTML Tidy, see www.w3.org">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link type="text/css" rel="stylesheet" href="style.css"><!-- Generated by The Open Group's rhtm tool v1.2.1 -->
<!-- Copyright (c) 2001 The Open Group, All Rights Reserved -->
<title>setsid</title>
</head>
<body bgcolor="white">
<basefont size="3"> <a name="setsid"></a> <a name="tag_03_667"></a><!-- setsid -->
<!--header start-->
<center><font size="2">The Open Group Base Specifications Issue 6<br>
IEEE Std 1003.1-2001<br>
Copyright &copy; 2001 The IEEE and The Open Group, All Rights reserved.</font></center>
<!--header end-->
<hr size="2" noshade>
<h4><a name="tag_03_667_01"></a>NAME</h4>
<blockquote>setsid - create session and set process group ID</blockquote>
<h4><a name="tag_03_667_02"></a>SYNOPSIS</h4>
<blockquote class="synopsis">
<p><code><tt>#include &lt;<a href="../basedefs/unistd.h.html">unistd.h</a>&gt;<br>
<br>
pid_t setsid(void);<br>
</tt></code></p>
</blockquote>
<h4><a name="tag_03_667_03"></a>DESCRIPTION</h4>
<blockquote>
<p>The <i>setsid</i>() function shall create a new session, if the calling process is not a process group leader. Upon return the
calling process shall be the session leader of this new session, shall be the process group leader of a new process group, and
shall have no controlling terminal. The process group ID of the calling process shall be set equal to the process ID of the calling
process. The calling process shall be the only process in the new process group and the only process in the new session.</p>
</blockquote>
<h4><a name="tag_03_667_04"></a>RETURN VALUE</h4>
<blockquote>
<p>Upon successful completion, <i>setsid</i>() shall return the value of the new process group ID of the calling process.
Otherwise, it shall return (<b>pid_t</b>)-1 and set <i>errno</i> to indicate the error.</p>
</blockquote>
<h4><a name="tag_03_667_05"></a>ERRORS</h4>
<blockquote>
<p>The <i>setsid</i>() function shall fail if:</p>
<dl compact>
<dt>[EPERM]</dt>
<dd>The calling process is already a process group leader, or the process group ID of a process other than the calling process
matches the process ID of the calling process.</dd>
</dl>
</blockquote>
<hr>
<div class="box"><em>The following sections are informative.</em></div>
<h4><a name="tag_03_667_06"></a>EXAMPLES</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_03_667_07"></a>APPLICATION USAGE</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_03_667_08"></a>RATIONALE</h4>
<blockquote>
<p>The <i>setsid</i>() function is similar to the <a href="../functions/setpgrp.html"><i>setpgrp</i>()</a> function of System V.
System V, without job control, groups processes into process groups and creates new process groups via <a href=
"../functions/setpgrp.html"><i>setpgrp</i>()</a>; only one process group may be part of a login session.</p>
<p>Job control allows multiple process groups within a login session. In order to limit job control actions so that they can only
affect processes in the same login session, this volume of IEEE&nbsp;Std&nbsp;1003.1-2001 adds the concept of a session that is
created via <i>setsid</i>(). The <i>setsid</i>() function also creates the initial process group contained in the session.
Additional process groups can be created via the <a href="../functions/setpgid.html"><i>setpgid</i>()</a> function. A System V
process group would correspond to a POSIX System Interfaces session containing a single POSIX process group. Note that this
function requires that the calling process not be a process group leader. The usual way to ensure this is true is to create a new
process with <a href="../functions/fork.html"><i>fork</i>()</a> and have it call <i>setsid</i>(). The <a href=
"../functions/fork.html"><i>fork</i>()</a> function guarantees that the process ID of the new process does not match any existing
process group ID.</p>
</blockquote>
<h4><a name="tag_03_667_09"></a>FUTURE DIRECTIONS</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_03_667_10"></a>SEE ALSO</h4>
<blockquote>
<p><a href="getsid.html"><i>getsid</i>()</a> , <a href="setpgid.html"><i>setpgid</i>()</a> , <a href=
"setpgrp.html"><i>setpgrp</i>()</a> , the Base Definitions volume of IEEE&nbsp;Std&nbsp;1003.1-2001, <a href=
"../basedefs/sys/types.h.html"><i>&lt;sys/types.h&gt;</i></a>, <a href="../basedefs/unistd.h.html"><i>&lt;unistd.h&gt;</i></a></p>
</blockquote>
<h4><a name="tag_03_667_11"></a>CHANGE HISTORY</h4>
<blockquote>
<p>First released in Issue 3. Included for alignment with the POSIX.1-1988 standard.</p>
</blockquote>
<h4><a name="tag_03_667_12"></a>Issue 6</h4>
<blockquote>
<p>In the SYNOPSIS, the optional include of the <a href="../basedefs/sys/types.h.html"><i>&lt;sys/types.h&gt;</i></a> header is
removed.</p>
<p>The following new requirements on POSIX implementations derive from alignment with the Single UNIX Specification:</p>
<ul>
<li>
<p>The requirement to include <a href="../basedefs/sys/types.h.html"><i>&lt;sys/types.h&gt;</i></a> has been removed. Although <a
href="../basedefs/sys/types.h.html"><i>&lt;sys/types.h&gt;</i></a> was required for conforming implementations of previous POSIX
specifications, it was not required for UNIX applications.</p>
</li>
</ul>
</blockquote>
<div class="box"><em>End of informative text.</em></div>
<hr>
<hr size="2" noshade>
<center><font size="2"><!--footer start-->
UNIX &reg; is a registered Trademark of The Open Group.<br>
POSIX &reg; is a registered Trademark of The IEEE.<br>
[ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href=
"../utilities/contents.html">XCU</a> | <a href="../functions/contents.html">XSH</a> | <a href="../xrat/contents.html">XRAT</a>
]</font></center>
<!--footer end-->
<hr size="2" noshade>
</body>
</html>