summaryrefslogtreecommitdiff
path: root/usr/src/man/man2/semop.2
blob: 8b21b5b3300f0aa11578d343685e96782ee3cd10 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
'\" te
.\" Copyright 1989 AT&T.
.\" Copyright (c) 2006, Sun Microsystems, Inc.  All Rights Reserved.
.\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
.\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
.TH SEMOP 2 "May 12, 2006"
.SH NAME
semop, semtimedop \- semaphore operations
.SH SYNOPSIS
.LP
.nf
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/sem.h>

\fBint\fR \fBsemop\fR(\fBint\fR \fIsemid\fR, \fBstruct sembuf *\fR\fIsops\fR, \fBsize_t\fR \fInsops\fR);
.fi

.LP
.nf
\fBint\fR \fBsemtimedop\fR(\fBint\fR \fIsemid\fR, \fBstruct sembuf *\fR\fIsops\fR, \fBsize_t\fR \fInsops\fR,
     \fBconst struct timespec *\fR\fItimeout\fR);
.fi

.SH DESCRIPTION
.sp
.LP
The \fBsemop()\fR function is used to perform atomically an array of semaphore
operations on the set of semaphores associated with the semaphore identifier
specified by \fIsemid\fR. The \fIsops\fR argument is a pointer to the array of
semaphore-operation structures. The \fInsops\fR argument is the number of such
structures in the array.
.sp
.LP
Each \fBsembuf\fR structure contains the following members:
.sp
.in +2
.nf
short	sem_num;	  /* semaphore number */
short	sem_op;	  /* semaphore operation */
short	sem_flg;	  /* operation flags */
.fi
.in -2

.sp
.LP
Each semaphore operation specified by \fBsem_op\fR is performed on the
corresponding semaphore specified by \fIsemid\fR and \fBsem_num\fR. The
permission required for a semaphore operation is given as {\fItoken\fR}, where
\fItoken\fR is the type of permission needed.  The types of permission are
interpreted as follows:
.sp
.in +2
.nf
00400    READ by user
00200    ALTER by user
00040    READ by group
00020    ALTER by group
00004    READ by others
00002    ALTER by others
.fi
.in -2

.sp
.LP
See the \fBSemaphore Operation Permissions\fR section of \fBIntro\fR(2) for
more information.
.sp
.LP
A process maintains a value, \fBsemadj\fR, for each semaphore it modifies. This
value contains the cumulative effect of operations the process has performed on
an individual semaphore with the \fBSEM_UNDO\fR flag set (so that they can be
undone if the process terminates unexpectedly).  The value of \fBsemadj\fR can
affect the behavior of calls to \fBsemop()\fR, \fBsemtimedop()\fR,
\fBexit()\fR, and \fB_exit()\fR (the latter two functions documented on
\fBexit\fR(2)), but is otherwise unobservable. See below for details.
.sp
.LP
The \fBsem_op\fR member specifies one of three semaphore operations:
.RS +4
.TP
1.
The \fBsem_op\fR member is a negative integer; {ALTER}
.RS +4
.TP
.ie t \(bu
.el o
If \fBsemval\fR (see \fBIntro\fR(2)) is greater than or equal to the absolute
value of \fBsem_op\fR, the absolute value of \fBsem_op\fR is subtracted from
\fBsemval\fR. Also, if (\fIsem_flg\fR\fB&SEM_UNDO\fR) is true, the absolute
value of \fBsem_op\fR is added to the calling process's \fBsemadj\fR value (see
\fBexit\fR(2)) for the specified semaphore.
.RE
.RS +4
.TP
.ie t \(bu
.el o
If \fBsemval\fR is less than the absolute value of \fBsem_op\fR and
(\fIsem_flg\fR\fB&IPC_NOWAIT\fR) is true, \fBsemop()\fR returns immediately.
.RE
.RS +4
.TP
.ie t \(bu
.el o
If \fBsemval\fR is less than the absolute value of \fBsem_op\fR and
(\fIsem_flg\fR\fB&IPC_NOWAIT\fR) is false, \fBsemop()\fR increments the
\fBsemncnt\fR associated with the specified semaphore and suspends execution of
the calling thread until one of the following conditions occur:
.RS +4
.TP
.ie t \(bu
.el o
The value of \fBsemval\fR becomes greater than or equal to the absolute value
of \fBsem_op\fR. When this occurs, the value of \fBsemncnt\fR associated with
the specified semaphore is decremented, the absolute value of \fBsem_op\fR is
subtracted from \fBsemval\fR and, if (\fIsem_flg\fR\fB&SEM_UNDO\fR) is true,
the absolute value of \fBsem_op\fR is added to the calling process's
\fBsemadj\fR value for the specified semaphore.
.RE
.RS +4
.TP
.ie t \(bu
.el o
The \fIsemid\fR for which the calling thread is awaiting action is removed from
the system (see \fBsemctl\fR(2)). When this occurs, \fBerrno\fR is set to
\fBEIDRM\fR and \fB\(mi1\fR is returned.
.RE
.RS +4
.TP
.ie t \(bu
.el o
The calling thread receives a signal that is to be caught. When this occurs,
the value of \fBsemncnt\fR associated with the specified semaphore is
decremented, and the calling thread resumes execution in the manner prescribed
in \fBsigaction\fR(2).
.RE
.RE
.RE
.RS +4
.TP
2.
The \fBsem_op\fR member is a positive integer; {ALTER}
.sp
The value of \fBsem_op\fR is added to \fBsemval\fR and, if
(\fIsem_flg\fR\fB&SEM_UNDO\fR) is true, the value of \fBsem_op\fR is subtracted
from the calling process's \fBsemadj\fR value for the specified semaphore.
.RE
.RS +4
.TP
3.
The \fBsem_op\fR member is 0; {READ}
.RS +4
.TP
.ie t \(bu
.el o
If \fBsemval\fR is 0, \fBsemop()\fR returns immediately.
.RE
.RS +4
.TP
.ie t \(bu
.el o
If \fBsemval\fR is not equal to 0 and (\fIsem_flg\fR\fB&IPC_NOWAIT\fR) is true,
\fBsemop()\fR returns immediately.
.RE
.RS +4
.TP
.ie t \(bu
.el o
If \fBsemval\fR is not equal to 0 and (\fIsem_flg\fR\fB&IPC_NOWAIT\fR) is
false, \fBsemop()\fR increments the \fBsemzcnt\fR associated with the specified
semaphore and suspends execution of the calling thread until one of the
following occurs:
.RS +4
.TP
.ie t \(bu
.el o
The value of \fBsemval\fR becomes 0, at which time the value of \fBsemzcnt\fR
associated with the specified semaphore is set to 0 and all processes waiting
on \fBsemval\fR to become 0 are awakened.
.RE
.RS +4
.TP
.ie t \(bu
.el o
The \fIsemid\fR for which the calling thread is awaiting action is removed from
the system. When this occurs, \fBerrno\fR is set to \fBEIDRM\fR and \fB\(mi1\fR
is returned.
.RE
.RS +4
.TP
.ie t \(bu
.el o
The calling thread receives a signal that is to be caught. When this occurs,
the value of \fBsemzcnt\fR associated with the specified semaphore is
decremented, and the calling thread resumes execution in the manner prescribed
in \fBsigaction\fR(2).
.RE
.RE
.RE
.sp
.LP
Upon successful completion, the value of \fBsempid\fR for each semaphore
specified in the array pointed to by \fIsops\fR is set to the process \fBID\fR
of the calling process.
.sp
.LP
The \fBsemtimedop()\fR function behaves as \fBsemop()\fR except when it must
suspend execution of the calling process to complete its operation.  If
\fBsemtimedop()\fR must suspend the calling process after the time interval
specified in \fItimeout\fR expires, or if the timeout expires while the process
is suspended, \fBsemtimedop()\fR returns with an error. If the \fBtimespec\fR
structure pointed to by \fItimeout\fR is zero-valued and \fBsemtimedop()\fR
needs to suspend the calling process to complete the requested operation(s), it
returns immediately with an error. If \fItimeout\fR is the \fINULL\fR pointer,
the behavior of \fBsemtimedop()\fR is identical to that of \fBsemop()\fR.
.SH RETURN VALUES
.sp
.LP
Upon successful completion, \fB0\fR is returned. Otherwise, \fB\(mi1\fR is
returned and \fBerrno\fR is set to indicate the error.
.SH ERRORS
.sp
.LP
The \fBsemop()\fR and \fBsemtimedop()\fR functions will fail if:
.sp
.ne 2
.na
\fB\fBE2BIG\fR\fR
.ad
.RS 10n
The \fInsops\fR argument is greater than the system-imposed maximum. See NOTES.
.RE

.sp
.ne 2
.na
\fB\fBEACCES\fR\fR
.ad
.RS 10n
Operation permission is denied to the calling process (see \fBIntro\fR(2)).
.RE

.sp
.ne 2
.na
\fB\fBEAGAIN\fR\fR
.ad
.RS 10n
The operation would result in suspension of the calling process but
(\fIsem_flg\fR\fB&IPC_NOWAIT\fR) is true.
.RE

.sp
.ne 2
.na
\fB\fBEFAULT\fR\fR
.ad
.RS 10n
The \fIsops\fR argument points to an illegal address.
.RE

.sp
.ne 2
.na
\fB\fBEFBIG\fR\fR
.ad
.RS 10n
The value of \fBsem_num\fR is less than 0 or greater than or equal to the
number of semaphores in the set associated with \fIsemid\fR.
.RE

.sp
.ne 2
.na
\fB\fBEIDRM\fR\fR
.ad
.RS 10n
A \fIsemid\fR was removed from the system.
.RE

.sp
.ne 2
.na
\fB\fBEINTR\fR\fR
.ad
.RS 10n
A signal was received.
.RE

.sp
.ne 2
.na
\fB\fBEINVAL\fR\fR
.ad
.RS 10n
The \fIsemid\fR argument is not a valid semaphore identifier, or the number of
individual semaphores for which the calling process requests a \fBSEM_UNDO\fR
operation would exceed the system-imposed limit. Solaris does not impose a
limit on the number of individual semaphores for which the calling process
requests a \fBSEM_UNDO\fR operation.
.RE

.sp
.ne 2
.na
\fB\fBENOSPC\fR\fR
.ad
.RS 10n
The limit on the number of individual processes requesting a \fBSEM_UNDO\fR
operation would be exceeded. Solaris does not impose a limit on the number of
individual processes requesting an \fBSEM_UNDO\fR operation.
.RE

.sp
.ne 2
.na
\fB\fBERANGE\fR\fR
.ad
.RS 10n
An operation would cause a \fBsemval\fR or a \fBsemadj\fR value to overflow the
system-imposed limit.
.RE

.sp
.LP
The \fBsemtimedop()\fR function will fail if:
.sp
.ne 2
.na
\fB\fBEAGAIN\fR\fR
.ad
.RS 10n
The timeout expired before the requested operation could be completed.
.RE

.sp
.LP
The \fBsemtimedop()\fR function will fail if one of the following is detected:
.sp
.ne 2
.na
\fB\fBEFAULT\fR\fR
.ad
.RS 10n
The \fItimeout\fR argument points to an illegal address.
.RE

.sp
.ne 2
.na
\fB\fBEINVAL\fR\fR
.ad
.RS 10n
The \fItimeout\fR argument specified a \fBtv_sec\fR or \fBtv_nsec\fR value less
than 0, or a \fBtv_nsec\fR value greater than or equal to 1000 million.
.RE

.SH ATTRIBUTES
.sp
.LP
See \fBattributes\fR(7) for descriptions of the following attributes:
.sp

.sp
.TS
box;
c | c
l | l .
ATTRIBUTE TYPE	ATTRIBUTE VALUE
_
Interface Stability	\fBsemop()\fR is Standard.
.TE

.SH SEE ALSO
.sp
.LP
.BR ipcs (1),
.BR Intro (2),
.BR exec (2),
.BR exit (2),
.BR fork (2),
.BR semctl (2),
.BR semget (2),
.BR setrctl (2),
.BR sigaction (2),
.BR attributes (7),
.BR standards (7),
.BR rctladm (8)
.SH NOTES
.sp
.LP
The system-imposed maximum on \fInsops\fR for a semaphore identifier is the
minimum enforced value of the \fBprocess.max-sem-ops\fR resource control of the
creating process at the time \fBsemget\fR(2) was used to allocate the
identifier.
.sp
.LP
See \fBrctladm\fR(8) and \fBsetrctl\fR(2) for information about using resource
controls.