📄 semop.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-2004 IEEE and The Open Group, All Rights Reserved --><title>semop</title></head><body bgcolor="white"><script type="text/javascript" language="JavaScript" src="../jscript/codes.js"></script><basefont size="3"> <a name="semop"></a> <a name="tag_03_640"></a><!-- semop --> <!--header start--><center><font size="2">The Open Group Base Specifications Issue 6<br>IEEE Std 1003.1, 2004 Edition<br>Copyright © 2001-2004 The IEEE and The Open Group, All Rights reserved.</font></center><!--header end--><hr size="2" noshade><h4><a name="tag_03_640_01"></a>NAME</h4><blockquote>semop - XSI semaphore operations</blockquote><h4><a name="tag_03_640_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 <<a href="../basedefs/sys/sem.h.html">sys/sem.h</a>><br><br> int semop(int</tt> <i>semid</i><tt>, struct sembuf *</tt><i>sops</i><tt>, size_t</tt> <i>nsops</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_640_03"></a>DESCRIPTION</h4><blockquote><p>The <i>semop</i>() function operates on XSI semaphores (see the Base Definitions volume of IEEE Std 1003.1-2001, <ahref="../basedefs/xbd_chap04.html#tag_04_15">Section 4.15, Semaphore</a>). It is unspecified whether this function interoperateswith the realtime interprocess communication facilities defined in <a href="xsh_chap02_08.html#tag_02_08"><i>Realtime</i></a>.</p><p>The <i>semop</i>() function shall perform atomically a user-defined array of semaphore operations on the set of semaphoresassociated with the semaphore identifier specified by the argument <i>semid</i>.</p><p>The argument <i>sops</i> is a pointer to a user-defined array of semaphore operation structures. The implementation shall notmodify elements of this array unless the application uses implementation-defined extensions.</p><p>The argument <i>nsops</i> is the number of such structures in the array.</p><p>Each structure, <b>sembuf</b>, includes the following members:</p><center><table border="1" cellpadding="3" align="center"><tr valign="top"><th align="center"><p class="tent"><b>Member Type</b></p></th><th align="center"><p class="tent"><b>Member Name</b></p></th><th align="center"><p class="tent"><b>Description</b></p></th></tr><tr valign="top"><td align="left"><p class="tent"><b>short</b></p></td><td align="left"><p class="tent"><i>sem_num</i></p></td><td align="left"><p class="tent">Semaphore number.</p></td></tr><tr valign="top"><td align="left"><p class="tent"><b>short</b></p></td><td align="left"><p class="tent"><i>sem_op</i></p></td><td align="left"><p class="tent">Semaphore operation.</p></td></tr><tr valign="top"><td align="left"><p class="tent"><b>short</b></p></td><td align="left"><p class="tent"><i>sem_flg</i></p></td><td align="left"><p class="tent">Operation flags.</p></td></tr></table></center><p>Each semaphore operation specified by <i>sem_op</i> is performed on the corresponding semaphore specified by <i>semid</i> and<i>sem_num</i>.</p><p>The variable <i>sem_op</i> specifies one of three semaphore operations:</p><ol><li><p>If <i>sem_op</i> is a negative integer and the calling process has alter permission, one of the following shall occur:</p><ul><li><p>If <i>semval</i>(see <a href="../basedefs/sys/sem.h.html"><i><sys/sem.h></i></a>) is greater than or equal to the absolutevalue of <i>sem_op</i>, the absolute value of <i>sem_op</i> is subtracted from <i>semval</i>. Also, if (<i>sem_flg</i>&SEM_UNDO) is non-zero, the absolute value of <i>sem_op</i> shall be added to the calling process' <i>semadj</i> value for thespecified semaphore.</p></li><li><p>If <i>semval</i> is less than the absolute value of <i>sem_op</i> and (<i>sem_flg</i> &IPC_NOWAIT) is non-zero,<i>semop</i>() shall return immediately.</p></li><li><p>If <i>semval</i> is less than the absolute value of <i>sem_op</i> and (<i>sem_flg</i> &IPC_NOWAIT) is 0, <i>semop</i>()shall increment the <i>semncnt</i> associated with the specified semaphore and suspend execution of the calling thread until one ofthe following conditions occurs:</p><ul><li><p>The value of <i>semval</i> becomes greater than or equal to the absolute value of <i>sem_op</i>. When this occurs, the value of<i>semncnt</i> associated with the specified semaphore shall be decremented, the absolute value of <i>sem_op</i> shall besubtracted from <i>semval</i> and, if (<i>sem_flg</i> &SEM_UNDO) is non-zero, the absolute value of <i>sem_op</i> shall beadded to the calling process' <i>semadj</i> value for the specified semaphore.</p></li><li><p>The <i>semid</i> for which the calling thread is awaiting action is removed from the system. When this occurs, <i>errno</i>shall be set equal to [EIDRM] and -1 shall be returned.</p></li><li><p>The calling thread receives a signal that is to be caught. When this occurs, the value of <i>semncnt</i> associated with thespecified semaphore shall be decremented, and the calling thread shall resume execution in the manner prescribed in <a href="sigaction.html"><i>sigaction</i>()</a>.</p></li></ul></li></ul></li><li><p>If <i>sem_op</i> is a positive integer and the calling process has alter permission, the value of <i>sem_op</i> shall be addedto <i>semval</i> and, if (<i>sem_flg</i> &SEM_UNDO) is non-zero, the value of <i>sem_op</i> shall be subtracted from thecalling process' <i>semadj</i> value for the specified semaphore.</p></li><li><p>If <i>sem_op</i> is 0 and the calling process has read permission, one of the following shall occur:</p><ul><li><p>If <i>semval</i> is 0, <i>semop</i>() shall return immediately.</p></li><li><p>If <i>semval</i> is non-zero and (<i>sem_flg</i> &IPC_NOWAIT) is non-zero, <i>semop</i>() shall return immediately.</p></li><li><p>If <i>semval</i> is non-zero and (<i>sem_flg</i> &IPC_NOWAIT) is 0, <i>semop</i>() shall increment the <i>semzcnt</i>associated with the specified semaphore and suspend execution of the calling thread until one of the following occurs:</p><ul><li><p>The value of <i>semval</i> becomes 0, at which time the value of <i>semzcnt</i> associated with the specified semaphore shall bedecremented.</p></li><li><p>The <i>semid</i> for which the calling thread is awaiting action is removed from the system. When this occurs, <i>errno</i>shall be set equal to [EIDRM] and -1 shall be returned.</p></li><li><p>The calling thread receives a signal that is to be caught. When this occurs, the value of <i>semzcnt</i> associated with thespecified semaphore shall be decremented, and the calling thread shall resume execution in the manner prescribed in <a href="sigaction.html"><i>sigaction</i>()</a>.</p></li></ul></li></ul></li></ol><p>Upon successful completion, the value of <i>sempid</i> for each semaphore specified in the array pointed to by <i>sops</i> shallbe set equal to the process ID of the calling process.</p></blockquote><h4><a name="tag_03_640_04"></a>RETURN VALUE</h4><blockquote><p>Upon successful completion, <i>semop</i>() shall return 0; otherwise, it shall return -1 and set <i>errno</i> to indicate theerror.</p></blockquote><h4><a name="tag_03_640_05"></a>ERRORS</h4><blockquote><p>The <i>semop</i>() function shall fail if:</p>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -