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

276 lines
10 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>semctl</title>
</head>
<body bgcolor="white">
<script type="text/javascript" language="JavaScript" src="../jscript/codes.js">
</script>
<basefont size="3"> <a name="semctl"></a> <a name="tag_03_638"></a><!-- semctl -->
<!--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_638_01"></a>NAME</h4>
<blockquote>semctl - XSI semaphore control operations</blockquote>
<h4><a name="tag_03_638_02"></a>SYNOPSIS</h4>
<blockquote class="synopsis">
<div class="box"><code><tt><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt=
"[Option Start]" border="0"> #include&nbsp;&lt;sys/sem.h&gt;<br>
<br>
int semctl(int</tt> <i>semid</i><tt>, int</tt> <i>semnum</i><tt>, int</tt> <i>cmd</i><tt>, ...); <img src="../images/opt-end.gif"
alt="[Option End]" border="0"></tt></code></div>
<tt><br>
</tt></blockquote>
<h4><a name="tag_03_638_03"></a>DESCRIPTION</h4>
<blockquote>
<p>The <i>semctl</i>() function operates on XSI semaphores (see the Base Definitions volume of IEEE&nbsp;Std&nbsp;1003.1-2001, <a
href="../basedefs/xbd_chap04.html#tag_04_15">Section 4.15, Semaphore</a>). It is unspecified whether this function interoperates
with the realtime interprocess communication facilities defined in <a href="xsh_chap02_08.html#tag_02_08"><i>Realtime</i></a> .</p>
<p>The <i>semctl</i>() function provides a variety of semaphore control operations as specified by <i>cmd</i>. The fourth argument
is optional and depends upon the operation requested. If required, it is of type <b>union semun</b>, which the application shall
explicitly declare:</p>
<pre>
<tt>union semun {
int val;
struct semid_ds *buf;
unsigned short *array;
} arg;
</tt>
</pre>
<p>The following semaphore control operations as specified by <i>cmd</i> are executed with respect to the semaphore specified by
<i>semid</i> and <i>semnum</i>. The level of permission required for each operation is shown with each command; see <a href=
"xsh_chap02_07.html#tag_02_07"><i>XSI Interprocess Communication</i></a> . The symbolic names for the values of <i>cmd</i> are
defined in the <a href="../basedefs/sys/sem.h.html"><i>&lt;sys/sem.h&gt;</i></a> header:</p>
<dl compact>
<dt>GETVAL</dt>
<dd>Return the value of <i>semval</i>; see <a href="../basedefs/sys/sem.h.html"><i>&lt;sys/sem.h&gt;</i></a>. Requires read
permission.</dd>
<dt>SETVAL</dt>
<dd>Set the value of <i>semval</i> to <i>arg.val</i>, where <i>arg</i> is the value of the fourth argument to <i>semctl</i>(). When
this command is successfully executed, the <i>semadj</i> value corresponding to the specified semaphore in all processes is
cleared. Requires alter permission; see <a href="xsh_chap02_07.html#tag_02_07"><i>XSI Interprocess Communication</i></a> .</dd>
<dt>GETPID</dt>
<dd>Return the value of <i>sempid</i>. Requires read permission.</dd>
<dt>GETNCNT</dt>
<dd>Return the value of <i>semncnt</i>. Requires read permission.</dd>
<dt>GETZCNT</dt>
<dd>Return the value of <i>semzcnt</i>. Requires read permission.</dd>
</dl>
<p>The following values of <i>cmd</i> operate on each <i>semval</i> in the set of semaphores:</p>
<dl compact>
<dt>GETALL</dt>
<dd>Return the value of <i>semval</i> for each semaphore in the semaphore set and place into the array pointed to by
<i>arg.array</i>, where <i>arg</i> is the fourth argument to <i>semctl</i>(). Requires read permission.</dd>
<dt>SETALL</dt>
<dd>Set the value of <i>semval</i> for each semaphore in the semaphore set according to the array pointed to by <i>arg.array</i>,
where <i>arg</i> is the fourth argument to <i>semctl</i>(). When this command is successfully executed, the <i>semadj</i> values
corresponding to each specified semaphore in all processes are cleared. Requires alter permission.</dd>
</dl>
<p>The following values of <i>cmd</i> are also available:</p>
<dl compact>
<dt>IPC_STAT</dt>
<dd>Place the current value of each member of the <b>semid_ds</b> data structure associated with <i>semid</i> into the structure
pointed to by <i>arg.buf</i>, where <i>arg</i> is the fourth argument to <i>semctl</i>(). The contents of this structure are
defined in <a href="../basedefs/sys/sem.h.html"><i>&lt;sys/sem.h&gt;</i></a>. Requires read permission.</dd>
<dt>IPC_SET</dt>
<dd>Set the value of the following members of the <b>semid_ds</b> data structure associated with <i>semid</i> to the corresponding
value found in the structure pointed to by <i>arg.buf</i>, where <i>arg</i> is the fourth argument to <i>semctl</i>():
<pre>
<tt>sem_perm.uid
sem_perm.gid
sem_perm.mode
</tt>
</pre>
<p>The mode bits specified in <a href="xsh_chap02_07.html#tag_02_07_01"><i>IPC General Description</i></a> are copied into the
corresponding bits of the <i>sem_perm.mode</i> associated with <i>semid</i>. The stored values of any other bits are
unspecified.</p>
<p>This command can only be executed by a process that has an effective user ID equal to either that of a process with appropriate
privileges or to the value of <i>sem_perm.cuid</i> or <i>sem_perm.uid</i> in the <b>semid_ds</b> data structure associated with
<i>semid</i>.</p>
</dd>
<dt>IPC_RMID</dt>
<dd>Remove the semaphore identifier specified by <i>semid</i> from the system and destroy the set of semaphores and <b>semid_ds</b>
data structure associated with it. This command can only be executed by a process that has an effective user ID equal to either
that of a process with appropriate privileges or to the value of <i>sem_perm.cuid</i> or <i>sem_perm.uid</i> in the <b>semid_ds</b>
data structure associated with <i>semid</i>.</dd>
</dl>
</blockquote>
<h4><a name="tag_03_638_04"></a>RETURN VALUE</h4>
<blockquote>
<p>If successful, the value returned by <i>semctl</i>() depends on <i>cmd</i> as follows:</p>
<dl compact>
<dt>GETVAL</dt>
<dd>The value of <i>semval</i>.</dd>
<dt>GETPID</dt>
<dd>The value of <i>sempid</i>.</dd>
<dt>GETNCNT</dt>
<dd>The value of <i>semncnt</i>.</dd>
<dt>GETZCNT</dt>
<dd>The value of <i>semzcnt</i>.</dd>
<dt>All others</dt>
<dd>0.</dd>
</dl>
<p>Otherwise, <i>semctl</i>() shall return -1 and set <i>errno</i> to indicate the error.</p>
</blockquote>
<h4><a name="tag_03_638_05"></a>ERRORS</h4>
<blockquote>
<p>The <i>semctl</i>() function shall fail if:</p>
<dl compact>
<dt>[EACCES]</dt>
<dd>Operation permission is denied to the calling process; see <a href="xsh_chap02_07.html#tag_02_07"><i>XSI Interprocess
Communication</i></a> .</dd>
<dt>[EINVAL]</dt>
<dd>The value of <i>semid</i> is not a valid semaphore identifier, or the value of <i>semnum</i> is less than 0 or greater than or
equal to <i>sem_nsems</i>, or the value of <i>cmd</i> is not a valid command.</dd>
<dt>[EPERM]</dt>
<dd>The argument <i>cmd</i> is equal to IPC_RMID or IPC_SET and the effective user ID of the calling process is not equal to that
of a process with appropriate privileges and it is not equal to the value of <i>sem_perm.cuid</i> or <i>sem_perm.uid</i> in the
data structure associated with <i>semid</i>.</dd>
<dt>[ERANGE]</dt>
<dd>The argument <i>cmd</i> is equal to SETVAL or SETALL and the value to which <i>semval</i> is to be set is greater than the
system-imposed maximum.</dd>
</dl>
</blockquote>
<hr>
<div class="box"><em>The following sections are informative.</em></div>
<h4><a name="tag_03_638_06"></a>EXAMPLES</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_03_638_07"></a>APPLICATION USAGE</h4>
<blockquote>
<p>The fourth parameter in the SYNOPSIS section is now specified as <tt>"..."</tt> in order to avoid a clash with the ISO&nbsp;C
standard when referring to the union <i>semun</i> (as defined in Issue 3) and for backwards-compatibility.</p>
<p>The POSIX Realtime Extension defines alternative interfaces for interprocess communication. Application developers who need to
use IPC should design their applications so that modules using the IPC routines described in <a href=
"xsh_chap02_07.html#tag_02_07"><i>XSI Interprocess Communication</i></a> can be easily modified to use the alternative
interfaces.</p>
</blockquote>
<h4><a name="tag_03_638_08"></a>RATIONALE</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_03_638_09"></a>FUTURE DIRECTIONS</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_03_638_10"></a>SEE ALSO</h4>
<blockquote>
<p><a href="xsh_chap02_07.html#tag_02_07"><i>XSI Interprocess Communication</i></a> , <a href=
"xsh_chap02_08.html#tag_02_08"><i>Realtime</i></a> , <a href="semget.html"><i>semget</i>()</a> , <a href=
"semop.html"><i>semop</i>()</a> , <a href="sem_close.html"><i>sem_close</i>()</a> , <a href=
"sem_destroy.html"><i>sem_destroy</i>()</a> , <a href="sem_getvalue.html"><i>sem_getvalue</i>()</a> , <a href=
"sem_init.html"><i>sem_init</i>()</a> , <a href="sem_open.html"><i>sem_open</i>()</a> , <a href=
"sem_post.html"><i>sem_post</i>()</a> , <a href="sem_unlink.html"><i>sem_unlink</i>()</a> , <a href=
"sem_wait.html"><i>sem_wait</i>()</a> , the Base Definitions volume of IEEE&nbsp;Std&nbsp;1003.1-2001, <a href=
"../basedefs/sys/sem.h.html"><i>&lt;sys/sem.h&gt;</i></a></p>
</blockquote>
<h4><a name="tag_03_638_11"></a>CHANGE HISTORY</h4>
<blockquote>
<p>First released in Issue 2. Derived from Issue 2 of the SVID.</p>
</blockquote>
<h4><a name="tag_03_638_12"></a>Issue 5</h4>
<blockquote>
<p>The note about use of POSIX Realtime Extension IPC routines has been moved from FUTURE DIRECTIONS to the APPLICATION USAGE
section.</p>
</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>