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 .Fn semop "int semid" "struct sembuf *array" "size_t 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
82 member in order to modify the behavior of the given operation.
84 The operation performed depends as follows on the value of
87 .\" This section is based on the description of semop() in
88 .\" Stevens, _Advanced Programming in the UNIX Environment_,
89 .\" and the semop(2) description in The Open Group Unix2 specification.
95 is positive and the process has alter permission,
96 the semaphore's value is incremented by
101 is specified, the semaphore's adjust on exit value is decremented by
106 generally corresponds to a process releasing a resource
107 associated with the semaphore.
111 is negative and the process has alter permission,
112 depends on the current value of the semaphore:
115 If the current value of the semaphore is greater than or equal to
116 the absolute value of
118 then the value is decremented by the absolute value of
122 is specified, the semaphore's adjust on exit
123 value is incremented by the absolute value of
126 If the current value of the semaphore is less than the absolute value of
128 one of the following happens:
129 .\" XXX a *second* sublist?
136 returns immediately with a return value of
139 Otherwise, the calling process is put to sleep until one of the following
140 conditions is satisfied:
141 .\" XXX We already have two sublists, why not a third?
144 Some other process removes the semaphore with the
150 returns immediately with a return value of
153 The process receives a signal that is to be caught.
154 In this case, the process will resume execution as defined by
158 value is greater than or equal to the absolute value of
160 When this condition becomes true, the semaphore's value is decremented
161 by the absolute value of
163 the semaphore's adjust on exit value is incremented by the
172 generally means that a process is waiting for a resource to become
177 is zero and the process has read permission,
178 one of the following will occur:
181 If the current value of the semaphore is equal to zero
184 can return immediately.
190 returns immediately with a return value of
193 Otherwise, the calling process is put to sleep until one of the following
194 conditions is satisfied:
195 .\" XXX Another nested sublists
198 Some other process removes the semaphore with the
204 returns immediately with a return value of
207 The process receives a signal that is to be caught.
208 In this case, the process will resume execution as defined by
211 The semaphore's value becomes zero.
216 For each semaphore a process has in use, the kernel maintains an
218 value, as alluded to earlier.
220 exits, either voluntarily or involuntarily, the adjust on exit value
221 for each semaphore is added to the semaphore's value.
223 be used to insure that a resource is released if a process terminates
230 system call will fail if:
233 No semaphore set corresponds to
235 or the process would exceed the system-defined limit for the number of
240 Permission denied due to mismatch between operation and mode of
243 The semaphore's value would have resulted in the process being put to sleep
248 Too many operations were specified.
252 .\" I'd have thought this would be EINVAL, but the source says
256 was not in the range of valid semaphores for the set.
258 The semaphore set was removed from the system.
262 system call was interrupted by a signal.
270 The requested operation would cause either
271 the semaphore's current value
273 or its adjust on exit value
275 to exceed the system-imposed limits.
285 may block waiting for memory even if