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.18 2003/01/25 21:27:37 alfred Exp $
28 .Dd September 22, 1995
33 .Nd atomic array of operations on a semaphore set
39 .Fa "struct sembuf *sops"
46 atomically performs the array of operations indicated by
48 on the semaphore set indicated by
54 Each operation is encoded in a
56 which is defined as follows:
62 u_short sem_num; /* semaphore # */
63 short sem_op; /* semaphore operation */
64 short sem_flg; /* operation flags */
73 determine an operation to be performed on semaphore number
84 member in order to modify the behavior of the given operation.
86 The operation performed depends as follows on the value of
89 .\" This section is based on the description of semop() in
90 .\" Stevens, _Advanced Programming in the UNIX Environment_,
91 .\" and the semop(2) description in The Open Group Unix2 specification.
97 is positive and the process has alter permission,
98 the semaphore's value is incremented by
103 is specified, the semaphore's adjust on exit value is decremented by
108 generally corresponds to a process releasing a resource
109 associated with the semaphore.
113 is negative and the process has alter permission,
114 depends on the current value of the semaphore:
117 If the current value of the semaphore is greater than or equal to
118 the absolute value of
120 then the value is decremented by the absolute value of
124 is specified, the semaphore's adjust on exit
125 value is incremented by the absolute value of
128 If the current value of the semaphore is less than the absolute value of
130 one of the following happens:
131 .\" XXX a *second* sublist?
138 returns immediately with a return value of
141 Otherwise, the calling process is put to sleep until one of the following
142 conditions is satisfied:
143 .\" XXX We already have two sublists, why not a third?
146 Some other process removes the semaphore with the
152 returns immediately with a return value of
155 The process receives a signal that is to be caught.
156 In this case, the process will resume execution as defined by
160 value is greater than or equal to the absolute value of
162 When this condition becomes true, the semaphore's value is decremented
163 by the absolute value of
165 the semaphore's adjust on exit value is incremented by the
174 generally means that a process is waiting for a resource to become
179 is zero and the process has read permission,
180 one of the following will occur:
183 If the current value of the semaphore is equal to zero
186 can return immediately.
192 returns immediately with a return value of
195 Otherwise, the calling process is put to sleep until one of the following
196 conditions is satisfied:
197 .\" XXX Another nested sublists
200 Some other process removes the semaphore with the
206 returns immediately with a return value of
209 The process receives a signal that is to be caught.
210 In this case, the process will resume execution as defined by
213 The semaphore's value becomes zero.
218 For each semaphore a process has in use, the kernel maintains an
220 value, as alluded to earlier.
222 exits, either voluntarily or involuntarily, the adjust on exit value
223 for each semaphore is added to the semaphore's value.
225 be used to insure that a resource is released if a process terminates
232 system call will fail if:
236 Too many operations are specified.
240 Permission is denied, due to a mismatch between the operation
241 and the mode of the semaphore set.
244 The semaphore's value would result
245 in the process being put to sleep and
251 .\" I'd have thought this would be EINVAL,
252 .\" but the source says EFBIG.
255 is not in the range of valid semaphores for the set.
258 The semaphore set is removed from the system.
263 system call is interrupted by a signal.
266 No semaphore set corresponds to
268 or the process would exceed the system-defined limit
269 for the number of per-process
281 The requested operation would cause either
282 the semaphore's current value
284 or its adjust-on-exit value
286 to exceed the system-imposed limits.
289 .Fd #include <sys/types.h>
290 .Fd #include <sys/ipc.h>
291 .Fd #include <sys/sem.h>
307 may block waiting for memory even if