⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 semctl.html

📁 unix 下的C开发手册,还用详细的例程。
💻 HTML
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html><head><!-- Copyright 1997 The Open Group, All Rights Reserved --><title>semctl</title></head><body bgcolor=white><center><font size=2>The Single UNIX &reg; Specification, Version 2<br>Copyright &copy; 1997 The Open Group</font></center><hr size=2 noshade><h4><a name = "tag_000_008_357">&nbsp;</a>NAME</h4><blockquote>semctl - semaphore control operations</blockquote><h4><a name = "tag_000_008_358">&nbsp;</a>SYNOPSIS</h4><blockquote><pre><code>#include&nbsp;&lt;sys/sem.h&gt;int semctl(int <i>semid</i>, int <i>semnum</i>, int <i>cmd</i>, ...);</code></pre></blockquote><h4><a name = "tag_000_008_359">&nbsp;</a>DESCRIPTION</h4><blockquote>The<i>semctl()</i>functionprovides 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 program must explicitly declare:<p><pre><code>union semun {            int val;            struct semid_ds *buf;            unsigned short  *array;} arg;</code></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 operationis shown with each command,see<a href="ipc.html">IPC</a>.The symbolic names for the values of<i>cmd</i>are defined by the<i><a href="syssem.h.html">&lt;sys/sem.h&gt;</a></i>header:<dl compact><dt>GETVAL<dd>Return the value of<i>semval</i>,see<i><a href="syssem.h.html">&lt;sys/sem.h&gt;</a></i>.Requires read permission.<dt>SETVAL<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="ipc.html">IPC</a>.<dt>GETPID<dd>Return the value of<i>sempid</i>.Requires read permission.<dt>GETNCNT<dd>Return the value of<i>semncnt</i>.Requires read permission.<dt>GETZCNT<dd>Return the value of<i>semzcnt</i>.Requires read permission.</dl><p>The following values of<i>cmd</i>operate on each<i>semval</i>in the set of semaphores:<dl compact><dt>GETALL<dd>Return the value of<i>semval</i>for each semaphore in the semaphore setand 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.<dt>SETALL<dd>Set the value of<i>semval</i>for each semaphore in the semaphore setaccording 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 allprocesses are cleared.Requires alter permission.</dl><p>The following values of<i>cmd</i>are also available:<dl compact><dt>IPC_STAT<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<i><a href="syssem.h.html">&lt;sys/sem.h&gt;</a></i>.Requires read permission.<dt>IPC_SET<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><code>sem_perm.uidsem_perm.gidsem_perm.mode</code></pre>The mode bits specified in<a href="ipc.html">IPC</a>are copied into the corresponding bits of the<b>sem_perm.mode</b>associated with<i>semid</i>.The stored values of any other bits are unspecified.This commandcan only be executed by a process thathas an effective user ID equal to either that ofa process with appropriate privileges or to the value of<b>sem_perm.cuid</b>or<b>sem_perm.uid</b>in the<b>semid_ds</b>data structure associated with<i>semid</i>.<dt>IPC_RMID<dd>Remove the semaphore-identifier specified by<i>semid</i>from the system and destroy the set ofsemaphores and<b>semid_ds</b>data structure associated with it.This commandcan only be executed by a process thathas an effective user ID equal to eitherthat of a process with appropriate privileges or to the value of<b>sem_perm.cuid</b>or<b>sem_perm.uid</b>in the<b>semid_ds</b>data structure associated with<i>semid</i>.</dl></blockquote><h4><a name = "tag_000_008_360">&nbsp;</a>RETURN VALUE</h4><blockquote>If successful, the value returned by<i>semctl()</i>depends on<i>cmd</i>as follows:<dl compact><dt>GETVAL<dd>The value of<i>semval</i>.<dt>GETPID<dd>The value of<i>sempid</i>.<dt>GETNCNT<dd>The value of<i>semncnt</i>.<dt>GETZCNT<dd>The value of<i>semzcnt</i>.<dt>All others<dd>0.</dl><p>Otherwise,<i>semctl()</i>returns -1 and<i>errno</i>indicates the error.</blockquote><h4><a name = "tag_000_008_361">&nbsp;</a>ERRORS</h4><blockquote>The<i>semctl()</i>function will fail if:<dl compact><dt>[EACCES]<dd>Operation permission is denied to the calling process, see<a href="ipc.html">IPC</a>.<dt>[EINVAL]<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.<dt>[EPERM]<dd>The argument<i>cmd</i>is equal to IPC_RMID or IPC_SETand the effective user ID of the calling processis not equal to that of a process with appropriate privileges andit is not equal to the value of<b>sem_perm.cuid</b>or<b>sem_perm.uid</b>in the data structure associated with<i>semid</i>.<dt>[ERANGE]<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.</dl></blockquote><h4><a name = "tag_000_008_362">&nbsp;</a>EXAMPLES</h4><blockquote>None.</blockquote><h4><a name = "tag_000_008_363">&nbsp;</a>APPLICATION USAGE</h4><blockquote>The fourth parameter in the SYNOPSIS section is now specified as<i>...</i>in order to avoid a clash with the ISO&nbsp;C standard when referring to the union<i>semun</i>(as defined in XPG3) and for backward compatibility.<p>The POSIX Realtime Extension defines alternative interfaces for interprocess communication.Application developers who need to use IPC should design theirapplications so that modules using the IPC routines described in<a href="ipc.html">IPC</a>can be easily modified to use the alternative interfaces.</blockquote><h4><a name = "tag_000_008_364">&nbsp;</a>FUTURE DIRECTIONS</h4><blockquote>None.</blockquote><h4><a name = "tag_000_008_365">&nbsp;</a>SEE ALSO</h4><blockquote><i><a href="semget.html">semget()</a></i>,<i><a href="semop.html">semop()</a></i>,<i><a href="sem_close.html">sem_close()</a></i>,<i><a href="sem_destroy.html">sem_destroy()</a></i>,<i><a href="sem_getvalue.html">sem_getvalue()</a></i>,<i><a href="sem_init.html">sem_init()</a></i>,<i><a href="sem_open.html">sem_open()</a></i>,<i><a href="sem_post.html">sem_post()</a></i>,<i><a href="sem_unlink.html">sem_unlink()</a></i>,<i><a href="sem_wait.html">sem_wait()</a></i>,<i><a href="syssem.h.html">&lt;sys/sem.h&gt;</a></i>,<a href="ipc.html">IPC</a>.</blockquote><h4>DERIVATION</h4><blockquote>Derived from Issue 2 of the SVID.</blockquote><hr size=2 noshade><center><font size=2>UNIX &reg; is a registered Trademark of The Open Group.<br>Copyright &copy; 1997 The Open Group<br> [ <a href="../index.html">Main Index</a> | <a href="../xshix.html">XSH</a> | <a href="../xcuix.html">XCU</a> | <a href="../xbdix.html">XBD</a> | <a href="../cursesix.html">XCURSES</a> | <a href="../xnsix.html">XNS</a> ]</font></center><hr size=2 noshade></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -