summaryrefslogtreecommitdiff
path: root/usr/src/man/man2/semctl.2
blob: 1ac4f6ab41553f2b6990a4f8dae20b844e6f38ac (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
'\" te
.\" Copyright 1989 AT&T.  Copyright (c) 2003, 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 SEMCTL 2 "Feb 1, 2003"
.SH NAME
semctl \- semaphore control operations
.SH SYNOPSIS
.LP
.nf
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/sem.h>

\fBint\fR \fBsemctl\fR(\fBint\fR \fIsemid\fR, \fBint\fR \fIsemnum\fR, \fBint\fR \fIcmd\fR...);
.fi

.SH DESCRIPTION
.sp
.LP
The \fBsemctl()\fR function provides a variety of semaphore control operations
as specified by \fIcmd\fR. The fourth argument is optional, depending upon the
operation  requested.  If required, it is of type  \fBunion semun\fR, which
must be explicitly declared by the application program.
.sp
.in +2
.nf
union semun {
        int             val;
        struct semid_ds *buf;
        ushort_t        *array;
} arg ;
.fi
.in -2

.sp
.LP
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 subsection of the
\fBDEFINITIONS\fR section of \fBIntro\fR(2) for more information. The following
semaphore operations as specified by \fIcmd\fR are executed with respect to the
semaphore specified by \fIsemid\fR and \fIsemnum\fR.
.sp
.ne 2
.na
\fB\fBGETVAL\fR\fR
.ad
.RS 11n
Return the value of  semval (see \fBIntro\fR(2)). {READ}
.RE

.sp
.ne 2
.na
\fB\fBSETVAL\fR\fR
.ad
.RS 11n
Set the value of  \fBsemval\fR to \fIarg.\fR\fIval\fR. {ALTER} When this
command is successfully executed, the \fBsemadj\fR value corresponding to the
specified semaphore in all processes is cleared.
.RE

.sp
.ne 2
.na
\fB\fBGETPID\fR\fR
.ad
.RS 11n
Return the value of \fB(int) sempid\fR. {READ}
.RE

.sp
.ne 2
.na
\fB\fBGETNCNT\fR\fR
.ad
.RS 11n
Return the value of \fBsemncnt\fR. {READ}
.RE

.sp
.ne 2
.na
\fB\fBGETZCNT\fR\fR
.ad
.RS 11n
Return the value of \fBsemzcnt\fR. {READ}
.RE

.sp
.LP
The following operations return and set, respectively, every \fBsemval\fR in
the set of semaphores.
.sp
.ne 2
.na
\fB\fBGETALL\fR\fR
.ad
.RS 10n
Place \fBsemval\fRs into array pointed to by \fIarg.\fR\fBarray\fR. {READ}
.RE

.sp
.ne 2
.na
\fB\fBSETALL\fR\fR
.ad
.RS 10n
Set \fBsemval\fRs according to the array pointed to by \fIarg.\fR\fBarray\fR.
{ALTER}. When this cmd is successfully executed, the \fBsemadj\fR values
corresponding to each specified semaphore in all processes are cleared.
.RE

.sp
.LP
The following operations are also available.
.sp
.ne 2
.na
\fB\fBIPC_STAT\fR\fR
.ad
.RS 12n
Place the current value of each member of the data structure associated with
\fIsemid\fR into the structure pointed to by \fIarg.\fR\fBbuf\fR. The contents
of this structure are defined in \fBIntro\fR(2). {READ}
.RE

.sp
.ne 2
.na
\fB\fBIPC_SET\fR\fR
.ad
.RS 12n
Set the value of the following members of the data structure associated with
\fIsemid\fR to the corresponding value found in the structure pointed to by
\fIarg\fR.\fBbuf\fR:
.sp
.in +2
.nf
sem_perm.uid
sem_perm.gid
sem_perm.mode	/* access permission bits only */
.fi
.in -2

This command can be executed only by a process that has either the
{\fBPRIV_IPC_OWNER\fR} privilege or an effective user \fBID\fR equal to the
value of \fBmsg_perm.cuid\fR or \fBmsg_perm.uid\fR in the data structure
associated with \fImsqid\fR. Only a process with the
{\fBPRIV_SYS_IPC_CONFIG\fR} privilege can raise the value of \fBmsg_qbytes\fR.
.RE

.sp
.ne 2
.na
\fB\fBIPC_RMID\fR\fR
.ad
.RS 12n
Remove the semaphore identifier specified by \fIsemid\fR from the system and
destroy the set of semaphores and data structure associated with it. This
command can be executed only by a process that has the {\fBPRIV_IPC_OWNER\fR}
privilege or an effective user \fBID\fR equal to the value of
\fBsem_perm.cuid\fR or \fBsem_perm.uid\fR in the data structure associated with
\fIsemid\fR.
.RE

.SH RETURN VALUES
.sp
.LP
Upon successful completion, the value returned depends on \fIcmd\fR as follows:
.sp
.ne 2
.na
\fB\fBGETVAL\fR\fR
.ad
.RS 11n
the value of \fBsemval\fR
.RE

.sp
.ne 2
.na
\fB\fBGETPID\fR\fR
.ad
.RS 11n
the value of \fB(int) sempid\fR
.RE

.sp
.ne 2
.na
\fB\fBGETNCNT\fR\fR
.ad
.RS 11n
the value of \fBsemncnt\fR
.RE

.sp
.ne 2
.na
\fB\fBGETZCNT\fR\fR
.ad
.RS 11n
the value of \fBsemzcnt\fR
.RE

.sp
.LP
All other successful completions return  \fB0\fR; otherwise, \fB\(mi1\fR is
returned and \fBerrno\fR is set to indicate the error.
.SH ERRORS
.sp
.LP
The \fBsemctl()\fR function will fail if:
.sp
.ne 2
.na
\fB\fBEACCES\fR\fR
.ad
.RS 13n
Operation permission is denied to the calling process (see \fBIntro\fR(2)).
.RE

.sp
.ne 2
.na
\fB\fBEFAULT\fR\fR
.ad
.RS 13n
The source or target is not a valid address in the user process.
.RE

.sp
.ne 2
.na
\fB\fBEINVAL\fR\fR
.ad
.RS 13n
The \fIsemid\fR argument is not a valid semaphore identifier; the \fIsemnum\fR
argument is less than 0 or greater than \fBsem_nsems\fR \(mi1; or the \fIcmd\fR
argument is not a valid command or is \fBIPC_SET\fR and \fBsem_perm.uid\fR or
\fBsem_perm.gid\fR is not valid.
.RE

.sp
.ne 2
.na
\fB\fBEPERM\fR\fR
.ad
.RS 13n
The \fIcmd\fR argument is equal to \fBIPC_RMID\fR or \fBIPC_SET\fR, the
effective user ID of the calling process is not equal to the value of
\fBsem_perm.cuid\fR or \fBsem_perm.uid\fR in the data structure associated with
\fIsemid\fR, and {\fBPRIV_IPC_OWNER\fR} is not asserted in the effective set of
the calling process.
.RE

.sp
.ne 2
.na
\fB\fBEOVERFLOW\fR\fR
.ad
.RS 13n
The \fIcmd\fR argument is \fBIPC_STAT\fR and \fIuid\fR or \fIgid\fR is too
large to be stored in the structure pointed to by \fIarg.buf\fR.
.RE

.sp
.ne 2
.na
\fB\fBERANGE\fR\fR
.ad
.RS 13n
The \fIcmd\fR argument is \fBSETVAL\fR or \fBSETALL\fR and the value to which
\fBsemval\fR is to be set is greater than the system imposed maximum.
.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	Standard
.TE

.SH SEE ALSO
.sp
.LP
.BR ipcs (1),
.BR Intro (2),
.BR semget (2),
.BR semop (2),
.BR attributes (7),
.BR privileges (7),
.BR standards (7)