2 .\" Copyright (c) 1995 David Hovemeyer <daveho@infocom.com>
4 .\" All rights reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\" notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\" notice, this list of conditions and the following disclaimer in the
13 .\" documentation and/or other materials provided with the distribution.
15 .\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
16 .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 .\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
19 .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 .\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 .\" $FreeBSD: src/lib/libc/sys/semop.2,v 1.7.2.6 2001/12/14 18:34:01 ru Exp $
28 .Dd September 22, 1995
33 .Nd atomic array of operations on a semaphore set
41 .Fn semop "int semid" "struct sembuf array[]" "unsigned nops"
44 atomically performs the array of operations indicated by
46 on the semaphore set indicated by
52 Each operation is encoded in a
54 which is defined as follows:
60 u_short sem_num; /* semaphore # */
61 short sem_op; /* semaphore operation */
62 short sem_flg; /* operation flags */
71 determine an operation to be performed on semaphore number
73 in the set. The values SEM_UNDO and IPC_NOWAIT may be
77 member in order to modify the behavior of the given operation.
79 The operation performed depends as follows on the value of
82 .\" This section is based on the description of semop() in
83 .\" Stevens, _Advanced Programming in the UNIX Environment_.
89 is positive, the semaphore's value is incremented by
91 value. If SEM_UNDO is specified, the semaphore's adjust on exit
92 value is decremented by
94 value. A positive value for
96 generally corresponds to a process releasing a resource
97 associated with the semaphore.
101 is negative depends on the current value of the semaphore:
104 If the current value of the semaphore is greater than or equal to
105 the absolute value of
107 then the value is decremented by the absolute value of
109 If SEM_UNDO is specified, the semaphore's adjust on exit
110 value is incremented by the absolute value of
113 If the current value of the semaphore is less than
115 value, one of the following happens:
116 .\" XXX a *second* sublist?
119 If IPC_NOWAIT was specified, then
121 returns immediately with a return value of
124 If some other process has removed the semaphore with the IPC_RMID
129 returns immediately with a return value of
132 Otherwise, the calling process is put to sleep until the semaphore's
133 value is greater than or equal to the absolute value of
135 When this condition becomes true, the semaphore's value is decremented
136 by the absolute value of
138 and the semaphore's adjust on exit value is incremented by the
145 generally means that a process is waiting for a resource to become
151 is zero, the process waits for the semaphore's value to become zero.
152 If it is already zero, the call to
154 can return immediately. Otherwise, the calling process is put to
155 sleep until the semaphore's value becomes zero.
158 For each semaphore a process has in use, the kernel maintains an
159 `adjust on exit' value, as alluded to earlier. When a process
160 exits, either voluntarily or involuntarily, the adjust on exit value
161 for each semaphore is added to the semaphore's value. This can
162 be used to insure that a resource is released if a process terminates
171 No semaphore set corresponds to
174 Permission denied due to mismatch between operation and mode of
177 The semaphore's value was less than
179 and IPC_NOWAIT was specified.
181 Too many operations were specified.
184 .\" I'd have thought this would be EINVAL, but the source says
188 was not in the range of valid semaphores for the set.