1 .\" $NetBSD: semctl.2,v 1.20 2010/03/22 19:30:55 joerg Exp $
3 .\" Copyright (c) 1995 Frank van der Linden
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.
14 .\" 3. All advertising materials mentioning features or use of this software
15 .\" must display the following acknowledgement:
16 .\" This product includes software developed for the NetBSD Project
17 .\" by Frank van der Linden
18 .\" 4. The name of the author may not be used to endorse or promote products
19 .\" derived from this software without specific prior written permission
21 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 .\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 .\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 .Nd semaphore control operations
43 .Fn semctl "int semid" "int semnum" "int cmd" "..."
47 system call provides a number of control operations on the semaphore specified
52 The operation to be performed is specified in
55 The fourth argument is optional and depends upon the operation requested.
56 If required, it is a union of the following fields:
58 int val; /* value for SETVAL */
59 struct semid_ds *buf; /* buffer for IPC_{STAT,SET} */
60 u_short *array; /* array for GETALL \*[Am] SETALL */
69 commands is defined in
71 and contains the following members:
73 struct ipc_perm sem_perm; /* operation permissions */
74 unsigned short sem_nsems; /* number of sems in set */
75 time_t sem_otime; /* last operation time */
76 time_t sem_ctime; /* last change time */
81 structure used inside the
83 structure is defined in
85 and contains the following members:
87 uid_t cuid; /* creator user id */
88 gid_t cgid; /* creator group id */
89 uid_t uid; /* user id */
90 gid_t gid; /* group id */
91 mode_t mode; /* permission (lower 9 bits) */
95 provides the following operations:
96 .Bl -tag -width IPC_RMIDX
98 Return the value of the semaphore.
100 Set the value of the semaphore to
104 is the fourth argument to
107 Return the pid of the last process that did an operation on this semaphore.
109 Return the number of processes waiting to acquire the semaphore.
111 Return the number of processes waiting for the value of the semaphore to
114 Return the values of all the semaphores associated with
117 Set the values of all the semaphores that are associated with the semaphore
120 to the corresponding values in
124 is the fourth argument to
127 Gather information about a semaphore and place the information in the
128 structure pointed to by
132 is the fourth argument to
140 fields in the structure associated with the semaphore.
141 The values are taken from the corresponding fields in the structure
146 is the fourth argument to
148 This operation can only be executed by the super-user, or a process that
149 has an effective user id equal to either
153 in the data structure associated with the semaphore.
155 Remove the semaphores associated with
157 from the system and destroy the data structures associated with it.
158 Only the super-user or a process with an effective uid equal to the
162 values in the data structure associated with the semaphore can do this.
165 The permission to read or change a semaphore (see
169 field in the same way as is
172 but the effective uid can match either the
177 effective gid can match either
190 returns one of the values described above if successful.
191 All other operations will make
193 return 0 if no errors occur.
194 Otherwise \-1 is returned and
196 set to reflect the error.
202 The caller has no operation permission for this semaphore.
207 specifies an invalid address.
210 is not a valid message semaphore identifier.
213 is not a valid command.
220 and the caller is not the super-user, nor does
221 the effective uid match either the
225 fields of the data structure associated with the semaphore.
232 and the value to be set is greater than the system semaphore maximum value.
240 system call conforms to
243 Semaphores appeared in the first release of