2 .\" Copyright 1989 AT&T. Copyright (c) 2003, Sun Microsystems, Inc. All Rights Reserved
3 .\" 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.
4 .\" 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.
5 .\" 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]
6 .TH SEMCTL 2 "Feb 1, 2003"
8 semctl \- semaphore control operations
12 #include <sys/types.h>
16 \fBint\fR \fBsemctl\fR(\fBint\fR \fIsemid\fR, \fBint\fR \fIsemnum\fR, \fBint\fR \fIcmd\fR...);
22 The \fBsemctl()\fR function provides a variety of semaphore control operations
23 as specified by \fIcmd\fR. The fourth argument is optional, depending upon the
24 operation requested. If required, it is of type \fBunion semun\fR, which
25 must be explicitly declared by the application program.
39 The permission required for a semaphore operation is given as {\fItoken\fR},
40 where \fItoken\fR is the type of permission needed. The types of permission
41 are interpreted as follows:
56 See the \fBSemaphore Operation Permissions\fR subsection of the
57 \fBDEFINITIONS\fR section of \fBIntro\fR(2) for more information. The following
58 semaphore operations as specified by \fIcmd\fR are executed with respect to the
59 semaphore specified by \fIsemid\fR and \fIsemnum\fR.
66 Return the value of semval (see \fBIntro\fR(2)). {READ}
75 Set the value of \fBsemval\fR to \fIarg.\fR\fIval\fR. {ALTER} When this
76 command is successfully executed, the \fBsemadj\fR value corresponding to the
77 specified semaphore in all processes is cleared.
86 Return the value of \fB(int) sempid\fR. {READ}
95 Return the value of \fBsemncnt\fR. {READ}
104 Return the value of \fBsemzcnt\fR. {READ}
109 The following operations return and set, respectively, every \fBsemval\fR in
110 the set of semaphores.
117 Place \fBsemval\fRs into array pointed to by \fIarg.\fR\fBarray\fR. {READ}
126 Set \fBsemval\fRs according to the array pointed to by \fIarg.\fR\fBarray\fR.
127 {ALTER}. When this cmd is successfully executed, the \fBsemadj\fR values
128 corresponding to each specified semaphore in all processes are cleared.
133 The following operations are also available.
140 Place the current value of each member of the data structure associated with
141 \fIsemid\fR into the structure pointed to by \fIarg.\fR\fBbuf\fR. The contents
142 of this structure are defined in \fBIntro\fR(2). {READ}
151 Set the value of the following members of the data structure associated with
152 \fIsemid\fR to the corresponding value found in the structure pointed to by
159 sem_perm.mode /* access permission bits only */
163 This command can be executed only by a process that has either the
164 {\fBPRIV_IPC_OWNER\fR} privilege or an effective user \fBID\fR equal to the
165 value of \fBmsg_perm.cuid\fR or \fBmsg_perm.uid\fR in the data structure
166 associated with \fImsqid\fR. Only a process with the
167 {\fBPRIV_SYS_IPC_CONFIG\fR} privilege can raise the value of \fBmsg_qbytes\fR.
176 Remove the semaphore identifier specified by \fIsemid\fR from the system and
177 destroy the set of semaphores and data structure associated with it. This
178 command can be executed only by a process that has the {\fBPRIV_IPC_OWNER\fR}
179 privilege or an effective user \fBID\fR equal to the value of
180 \fBsem_perm.cuid\fR or \fBsem_perm.uid\fR in the data structure associated with
187 Upon successful completion, the value returned depends on \fIcmd\fR as follows:
194 the value of \fBsemval\fR
203 the value of \fB(int) sempid\fR
212 the value of \fBsemncnt\fR
221 the value of \fBsemzcnt\fR
226 All other successful completions return \fB0\fR; otherwise, \fB\(mi1\fR is
227 returned and \fBerrno\fR is set to indicate the error.
231 The \fBsemctl()\fR function will fail if:
238 Operation permission is denied to the calling process (see \fBIntro\fR(2)).
247 The source or target is not a valid address in the user process.
256 The \fIsemid\fR argument is not a valid semaphore identifier; the \fIsemnum\fR
257 argument is less than 0 or greater than \fBsem_nsems\fR \(mi1; or the \fIcmd\fR
258 argument is not a valid command or is \fBIPC_SET\fR and \fBsem_perm.uid\fR or
259 \fBsem_perm.gid\fR is not valid.
268 The \fIcmd\fR argument is equal to \fBIPC_RMID\fR or \fBIPC_SET\fR, the
269 effective user ID of the calling process is not equal to the value of
270 \fBsem_perm.cuid\fR or \fBsem_perm.uid\fR in the data structure associated with
271 \fIsemid\fR, and {\fBPRIV_IPC_OWNER\fR} is not asserted in the effective set of
278 \fB\fBEOVERFLOW\fR\fR
281 The \fIcmd\fR argument is \fBIPC_STAT\fR and \fIuid\fR or \fIgid\fR is too
282 large to be stored in the structure pointed to by \fIarg.buf\fR.
291 The \fIcmd\fR argument is \fBSETVAL\fR or \fBSETALL\fR and the value to which
292 \fBsemval\fR is to be set is greater than the system imposed maximum.
298 See \fBattributes\fR(5) for descriptions of the following attributes:
306 ATTRIBUTE TYPE ATTRIBUTE VALUE
308 Interface Stability Standard
314 \fBipcs\fR(1), \fBIntro\fR(2), \fBsemget\fR(2), \fBsemop\fR(2),
315 \fBattributes\fR(5), \fBprivileges\fR(5), \fBstandards\fR(5)