1semctl(2) System Calls semctl(2)
2
3
4
6 semctl - semaphore control operations
7
9 #include <sys/types.h>
10 #include <sys/ipc.h>
11 #include <sys/sem.h>
12
13 int semctl(int semid, int semnum, int cmd...);
14
15
17 The semctl() function provides a variety of semaphore control opera‐
18 tions as specified by cmd. The fourth argument is optional, depending
19 upon the operation requested. If required, it is of type union
20 semun, which must be explicitly declared by the application program.
21
22 union semun {
23 int val;
24 struct semid_ds *buf;
25 ushort_t *array;
26 } arg ;
27
28
29
30 The permission required for a semaphore operation is given as {token},
31 where token is the type of permission needed. The types of permission
32 are interpreted as follows:
33
34 00400 READ by user
35 00200 ALTER by user
36 00040 READ by group
37 00020 ALTER by group
38 00004 READ by others
39 00002 ALTER by others
40
41
42
43 See the Semaphore Operation Permissions subsection of the DEFINITIONS
44 section of Intro(2) for more information. The following semaphore oper‐
45 ations as specified by cmd are executed with respect to the semaphore
46 specified by semid and semnum.
47
48 GETVAL Return the value of semval (see Intro(2)). {READ}
49
50
51 SETVAL Set the value of semval to arg.val. {ALTER} When this com‐
52 mand is successfully executed, the semadj value correspond‐
53 ing to the specified semaphore in all processes is cleared.
54
55
56 GETPID Return the value of (int) sempid. {READ}
57
58
59 GETNCNT Return the value of semncnt. {READ}
60
61
62 GETZCNT Return the value of semzcnt. {READ}
63
64
65
66 The following operations return and set, respectively, every semval in
67 the set of semaphores.
68
69 GETALL Place semvals into array pointed to by arg.array. {READ}
70
71
72 SETALL Set semvals according to the array pointed to by arg.array.
73 {ALTER}. When this cmd is successfully executed, the semadj
74 values corresponding to each specified semaphore in all pro‐
75 cesses are cleared.
76
77
78
79 The following operations are also available.
80
81 IPC_STAT Place the current value of each member of the data struc‐
82 ture associated with semid into the structure pointed to by
83 arg.buf. The contents of this structure are defined in
84 Intro(2). {READ}
85
86
87 IPC_SET Set the value of the following members of the data struc‐
88 ture associated with semid to the corresponding value found
89 in the structure pointed to by arg.buf:
90
91 sem_perm.uid
92 sem_perm.gid
93 sem_perm.mode /* access permission bits only */
94
95 This command can be executed only by a process that has
96 either the {PRIV_IPC_OWNER} privilege or an effective user
97 ID equal to the value of msg_perm.cuid or msg_perm.uid in
98 the data structure associated with msqid. Only a process
99 with the {PRIV_SYS_IPC_CONFIG} privilege can raise the
100 value of msg_qbytes.
101
102
103 IPC_RMID Remove the semaphore identifier specified by semid from the
104 system and destroy the set of semaphores and data structure
105 associated with it. This command can be executed only by a
106 process that has the {PRIV_IPC_OWNER} privilege or an
107 effective user ID equal to the value of sem_perm.cuid or
108 sem_perm.uid in the data structure associated with semid.
109
110
112 Upon successful completion, the value returned depends on cmd as fol‐
113 lows:
114
115 GETVAL the value of semval
116
117
118 GETPID the value of (int) sempid
119
120
121 GETNCNT the value of semncnt
122
123
124 GETZCNT the value of semzcnt
125
126
127
128 All other successful completions return 0; otherwise, −1 is returned
129 and errno is set to indicate the error.
130
132 The semctl() function will fail if:
133
134 EACCES Operation permission is denied to the calling process (see
135 Intro(2)).
136
137
138 EFAULT The source or target is not a valid address in the user
139 process.
140
141
142 EINVAL The semid argument is not a valid semaphore identifier;
143 the semnum argument is less than 0 or greater than
144 sem_nsems −1; or the cmd argument is not a valid command
145 or is IPC_SET and sem_perm.uid or sem_perm.gid is not
146 valid.
147
148
149 EPERM The cmd argument is equal to IPC_RMID or IPC_SET, the
150 effective user ID of the calling process is not equal to
151 the value of sem_perm.cuid or sem_perm.uid in the data
152 structure associated with semid, and {PRIV_IPC_OWNER} is
153 not asserted in the effective set of the calling process.
154
155
156 EOVERFLOW The cmd argument is IPC_STAT and uid or gid is too large
157 to be stored in the structure pointed to by arg.buf.
158
159
160 ERANGE The cmd argument is SETVAL or SETALL and the value to
161 which semval is to be set is greater than the system
162 imposed maximum.
163
164
166 See attributes(5) for descriptions of the following attributes:
167
168
169
170
171 ┌─────────────────────────────┬─────────────────────────────┐
172 │ ATTRIBUTE TYPE │ ATTRIBUTE VALUE │
173 ├─────────────────────────────┼─────────────────────────────┤
174 │Interface Stability │Standard │
175 └─────────────────────────────┴─────────────────────────────┘
176
178 ipcs(1), Intro(2), semget(2), semop(2), attributes(5), privileges(5),
179 standards(5)
180
181
182
183SunOS 5.11 1 Feb 2003 semctl(2)