Penguin
Annotated edit history of semop(2) version 1, including all changes. View license author blame.
Rev Author # Line
1 perry 1 SEMOP
2 !!!SEMOP
3 NAME
4 SYNOPSIS
5 DESCRIPTION
6 RETURN VALUE
7 ERRORS
8 NOTES
9 BUGS
10 CONFORMING TO
11 SEE ALSO
12 ----
13 !!NAME
14
15
16 semop - semaphore operations
17 !!SYNOPSIS
18
19
20 __# include
21 ____int semop ( int__ ''semid''__, struct sembuf *__''sops''__, unsigned__ ''nsops'' __)__
22 !!DESCRIPTION
23
24
25 The function performs operations on selected members of the
26 semaphore set indicated by ''semid''. Each of the
27 ''nsops'' elements in the array pointed to by ''sops''
28 specify an operation to be performed on a semaphore by a
29 __struct sembuf__ including the following
30 members:
31
32
33 __short sem_num;__ /* semaphore number: 0 = first
34 */__
35 short sem_op;__ /* semaphore operation */__
36 short sem_flg;__ /* operation flags */
37
38
39 Flags recognized in __sem_flg__ are __IPC_NOWAIT__ and
40 __SEM_UNDO__. If an operation asserts __SEM_UNDO__, it
41 will be undone when the process exits.
42
43
44 The system call semantic assures that the operations will be
45 performed if and only if all of them will succeed. Each
46 operation is performed on the __sem_num__-th semaphore of
47 the semaphore set - where the first semaphore of the set is
48 semaphore __0__ - and is one among the following
49 three.
50
51
52 If __sem_op__ is a positive integer, the operation adds
53 this value to __semval__. Furthermore, if __SEM_UNDO__
54 is asserted for this operation, the system updates the
55 process undo count for this semaphore. The operation always
56 goes through, so no process sleeping can happen. The calling
57 process must have alter permissions on the semaphore
58 set.
59
60
61 If __sem_op__ is zero, the process must have read access
62 permissions on the semaphore set. If __semval__ is zero,
63 the operation goes through. Otherwise, if __IPC_NOWAIT__
64 is asserted in __sem_flg__, the system call fails
65 (undoing all previous actions performed) with __errno__
66 set to __EAGAIN__. Otherwise __semzcnt__ is
67 incremented by one and the process sleeps until one of the
68 following occurs:
69
70
71 __semval__ becomes 0, at which time the value of
72 __semzcnt__ is decremented.
73
74
75 The semaphore set is removed: the system call fails with
76 __errno__ set to __EIDRM__.
77
78
79 The calling process receives a signal that has to be caught:
80 the value of __semzcnt__ is decremented and the system
81 call fails with __errno__ set to
82 __EINTR__.
83
84
85 If __sem_op__ is less than zero, the process must have
86 alter permissions on the semaphore set. If __semval__ is
87 greater than or equal to the absolute value of
88 __sem_op__, the absolute value of __sem_op__ is
89 subtracted by __semval__. Furthermore, if __SEM_UNDO__
90 is asserted for this operation, the system updates the
91 process undo count for this semaphore. Then the operation
92 goes through. Otherwise, if __IPC_NOWAIT__ is asserted in
93 __sem_flg__, the system call fails (undoing all previous
94 actions performed) with __errno__ set to __EAGAIN__.
95 Otherwise __semncnt__ is incremented by one and the
96 process sleeps until one of the following
97 occurs:
98
99
100 __semval__ becomes greater or equal to the absolute value
101 of __sem_op__, at which time the value of __semncnt__
102 is decremented, the absolute value of __sem_op__ is
103 subtracted from __semval__ and, if __SEM_UNDO__ is
104 asserted for this operation, the system updates the process
105 undo count for this semaphore.
106
107
108 The semaphore set is removed from the system: the system
109 call fails with __errno__ set to
110 __EIDRM__.
111
112
113 The calling process receives a signal that has to be caught:
114 the value of __semncnt__ is decremented and the system
115 call fails with __errno__ set to
116 __EINTR__.
117
118
119 In case of success, the __sempid__ member of the
120 structure __sem__ for each semaphore specified in the
121 array pointed to by ''sops'' is set to the process-ID of
122 the calling process. Furthermore both __sem_otime__ and
123 __sem_ctime__ are set to the current time.
124 !!RETURN VALUE
125
126
127 If successful the system call returns __0__, otherwise it
128 returns __-1__ with __errno__ indicating the
129 error.
130 !!ERRORS
131
132
133 For a failing return, __errno__ will be set to one among
134 the following values:
135
136
137 __E2BIG__
138
139
140 The argument ''nsops'' is greater than __SEMOPM__, the
141 maximum number of operations allowed per system
142 call.
143
144
145 __EACCES__
146
147
148 The calling process has no access permissions on the
149 semaphore set as required by one of the specified
150 operations.
151
152
153 __EAGAIN__
154
155
156 An operation could not go through and __IPC_NOWAIT__ was
157 asserted in its ''sem_flg''__.__
158
159
160 __EFAULT__
161
162
163 The address pointed to by ''sops'' isn't
164 accessible.
165
166
167 __EFBIG__
168
169
170 For some operation the value of __sem_num__ is less than
171 0 or greater than or equal to the number of semaphores in
172 the set.
173
174
175 __EIDRM__
176
177
178 The semaphore set was removed.
179
180
181 __EINTR__
182
183
184 Sleeping on a wait queue, the process received a signal that
185 had to be caught.
186
187
188 __EINVAL__
189
190
191 The semaphore set doesn't exist, or ''semid'' is less
192 than zero, or ''nsops'' has a non-positive
193 value.
194
195
196 __ENOMEM__
197
198
199 The __sem_flg__ of some operation asserted
200 __SEM_UNDO__ and the system has not enough memory to
201 allocate the undo structure.
202
203
204 __ERANGE__
205
206
207 For some operation __semop+semval__ is greater than
208 __SEMVMX__, the implementation dependent maximum value
209 for __semval__.
210 !!NOTES
211
212
213 The __sem_undo__ structures of a process aren't inherited
214 by its child on execution of a fork(2) system call.
215 They are instead inherited by the substituting process
216 resulting by the execution of the execve(2) system
217 call.
218
219
220 The followings are limits on semaphore set resources
221 affecting a __semop__ call:
222
223
224 __SEMOPM__
225
226
227 Maximum number of operations allowed for one __semop__
228 call: policy dependent.
229
230
231 __SEMVMX__
232
233
234 Maximum allowable value for __semval__: implementation
235 dependent (32767).
236
237
238 The implementation has no intrinsic limits for the adjust on
239 exit maximum value (__SEMAEM__), the system wide maximum
240 number of undo structures (__SEMMNU__) and the per
241 process maximum number of undo entries system
242 parameters.
243 !!BUGS
244
245
246 The system maintains a per process __sem_undo__ structure
247 for each semaphore altered by the process with undo
248 requests. Those structures are free at process exit. One
249 major cause for unhappiness with the undo mechanism is that
250 it does not fit in with the notion of having an atomic set
251 of operations an array of semaphores. The undo requests for
252 an array and each semaphore therein may have been
253 accumulated over many __semopt__ calls. Should the
254 process sleep when exiting, or should all undo operations be
255 applied with the __IPC_NOWAIT__ flag in effect? Currently
256 those undo operations which go through immediately are
257 applied, and those that require a wait are ignored silently.
258 Thus harmless undo usage is guaranteed with private
259 semaphores only.
260 !!CONFORMING TO
261
262
263 SVr4, SVID. SVr4 documents additional error conditions
264 EINVAL, EFBIG, ENOSPC.
265 !!SEE ALSO
266
267
268 ipc(5), semctl(2),
269 semget(2)
270 ----
This page is a man page (or other imported legacy content). We are unable to automatically determine the license status of this page.