semget.html
来自「unix 下的C开发手册,还用详细的例程。」· HTML 代码 · 共 186 行
HTML
186 行
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html><head><!-- Copyright 1997 The Open Group, All Rights Reserved --><title>semget</title></head><body bgcolor=white><center><font size=2>The Single UNIX ® Specification, Version 2<br>Copyright © 1997 The Open Group</font></center><hr size=2 noshade><h4><a name = "tag_000_008_366"> </a>NAME</h4><blockquote>semget - get set of semaphores</blockquote><h4><a name = "tag_000_008_367"> </a>SYNOPSIS</h4><blockquote><pre><code>#include <<a href="syssem.h.html">sys/sem.h</a>>int semget(key_t <i>key</i>, int <i>nsems</i>, int <i>semflg</i>);</code></pre></blockquote><h4><a name = "tag_000_008_368"> </a>DESCRIPTION</h4><blockquote>The<i>semget()</i>function returns the semaphore identifier associated with<i>key</i>.<p>A semaphore identifier with its associated<b>semid_ds</b>data structure and its associated set of<i>nsems</i>semaphores,see<i><a href="syssem.h.html"><sys/sem.h></a></i>,are created for<i>key</i>if one of the following is true:<ul><p><li>The argument<i>key</i>is equal to IPC_PRIVATE .<p><li>The argument<i>key</i>does not already have a semaphore identifier associated with itand (<i>semflg</i> & IPC_CREAT) is non-zero.<p></ul><p>Upon creation, the<b>semid_ds</b>data structure associated with the new semaphore identifier isinitialised as follows:<ul><p><li>In the operation permissions structure<i>sem_perm.cuid</i>,<i>sem_perm.uid</i>,<i>sem_perm.cgid</i>and<i>sem_perm.gid</i>are set equal to the effective user IDand effective group ID,respectively, of the calling process.<p><li>The low-order 9 bits of<i>sem_perm.mode</i>are set equal to the low-order 9 bits of<i>semflg</i>.<p><li>The variable<i>sem_nsems</i>is set equal to the value of<i>nsems</i>.<p><li>The variable<i>sem_otime</i>is set equal to 0 and<i>sem_ctime</i>is set equal to the current time.<p><li>The data structure associated with each semaphore inthe set is not initialised.The<i><a href="semctl.html">semctl()</a></i>function with the command SETVAL or SETALLcan be used to initialise each semaphore.<p></ul></blockquote><h4><a name = "tag_000_008_369"> </a>RETURN VALUE</h4><blockquote>Upon successful completion,<i>semget()</i>returns a non-negative integer, namely a semaphore identifier;otherwise, it returns -1 and<i>errno</i>will be set to indicate the error.</blockquote><h4><a name = "tag_000_008_370"> </a>ERRORS</h4><blockquote>The<i>semget()</i>function will fail if:<dl compact><dt>[EACCES]<dd>A semaphore identifier exists for<i>key</i>,but operation permission as specified by the low-order 9 bits of<i>semflg</i>would not be granted. See<a href="ipc.html">IPC</a>.<dt>[EEXIST]<dd>A semaphore identifier exists for the argument<i>key</i>but ((<i>semflg</i>&IPC_CREAT)&&(<i>semflg</i>&IPC_EXCL))is non-zero.<dt>[EINVAL]<dd>The value of<i>nsems</i>is either less than or equal to 0 orgreater than the system-imposed limit,or a semaphore identifier exists for the argument<i>key</i>,but the number of semaphores in theset associated with it is less than<i>nsems</i>and<i>nsems</i>is not equal to 0.<dt>[ENOENT]<dd>A semaphore identifier does not exist for the argument<i>key</i>and (<i>semflg</i>&IPC_CREAT) is equal to 0.<dt>[ENOSPC]<dd>A semaphore identifier is to be created butthe system-imposed limit on the maximum number ofallowed semaphores system-wide would be exceeded.</dl></blockquote><h4><a name = "tag_000_008_371"> </a>EXAMPLES</h4><blockquote>None.</blockquote><h4><a name = "tag_000_008_372"> </a>APPLICATION USAGE</h4><blockquote>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_373"> </a>FUTURE DIRECTIONS</h4><blockquote>None.</blockquote><h4><a name = "tag_000_008_374"> </a>SEE ALSO</h4><blockquote><i><a href="semctl.html">semctl()</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"><sys/sem.h></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 ® is a registered Trademark of The Open Group.<br>Copyright © 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 + =
减小字号Ctrl + -
显示快捷键?