]>
Commit | Line | Data |
---|---|---|
fea681da | 1 | .\" Copyright 1993 Giorgio Ciucci (giorgio@crcc.it) |
c11b1abf | 2 | .\" and Copyright 2004, 2005 Michael Kerrisk <mtk.manpages@gmail.com> |
fea681da | 3 | .\" |
5fbde956 | 4 | .\" SPDX-License-Identifier: Linux-man-pages-copyleft |
fea681da MK |
5 | .\" |
6 | .\" Modified Tue Oct 22 17:53:56 1996 by Eric S. Raymond <esr@thyrsus.com> | |
7 | .\" Modified Fri Jun 19 10:59:15 1998 by Andries Brouwer <aeb@cwi.nl> | |
8 | .\" Modified Sun Feb 18 01:59:29 2001 by Andries Brouwer <aeb@cwi.nl> | |
c11b1abf | 9 | .\" Modified 20 Dec 2001, Michael Kerrisk <mtk.manpages@gmail.com> |
fea681da | 10 | .\" Modified 21 Dec 2001, aeb |
c11b1abf | 11 | .\" Modified 27 May 2004, Michael Kerrisk <mtk.manpages@gmail.com> |
fea681da | 12 | .\" Added notes on CAP_IPC_OWNER requirement |
c11b1abf | 13 | .\" Modified 17 Jun 2004, Michael Kerrisk <mtk.manpages@gmail.com> |
fea681da | 14 | .\" Added notes on CAP_SYS_ADMIN requirement for IPC_SET and IPC_RMID |
c11b1abf | 15 | .\" Modified, 11 Nov 2004, Michael Kerrisk <mtk.manpages@gmail.com> |
70d0e5ef MK |
16 | .\" Language and formatting clean-ups |
17 | .\" Rewrote semun text | |
18 | .\" Added semid_ds and ipc_perm structure definitions | |
24ed820a | 19 | .\" 2005-08-02, mtk: Added IPC_INFO, SEM_INFO, SEM_STAT descriptions. |
d2ff4f86 | 20 | .\" 2018-03-20, dbueso: Added SEM_STAT_ANY description. |
fea681da | 21 | .\" |
1d767b55 | 22 | .TH SEMCTL 2 2021-03-22 "Linux" "Linux Programmer's Manual" |
fea681da | 23 | .SH NAME |
47f065d6 | 24 | semctl \- System V semaphore control operations |
fea681da MK |
25 | .SH SYNOPSIS |
26 | .nf | |
fea681da | 27 | .B #include <sys/sem.h> |
68e4db0a | 28 | .PP |
fea681da MK |
29 | .BI "int semctl(int " semid ", int " semnum ", int " cmd ", ...);" |
30 | .fi | |
31 | .SH DESCRIPTION | |
540036b2 | 32 | .BR semctl () |
fea681da MK |
33 | performs the control operation specified by |
34 | .I cmd | |
efbfd7ec | 35 | on the System\ V semaphore set identified by |
fea681da MK |
36 | .IR semid , |
37 | or on the | |
38 | .IR semnum -th | |
39 | semaphore of that set. | |
70d0e5ef | 40 | (The semaphores in a set are numbered starting at 0.) |
fea681da | 41 | .PP |
70d0e5ef MK |
42 | This function has three or four arguments, depending on |
43 | .IR cmd . | |
44 | When there are four, the fourth has the type | |
45 | .IR "union semun" . | |
46 | The \fIcalling program\fP must define this union as follows: | |
efeece04 | 47 | .PP |
70d0e5ef | 48 | .in +4n |
b8302363 | 49 | .EX |
fea681da | 50 | union semun { |
70d0e5ef MK |
51 | int val; /* Value for SETVAL */ |
52 | struct semid_ds *buf; /* Buffer for IPC_STAT, IPC_SET */ | |
53 | unsigned short *array; /* Array for GETALL, SETALL */ | |
c13182ef | 54 | struct seminfo *__buf; /* Buffer for IPC_INFO |
d064d41a | 55 | (Linux\-specific) */ |
fea681da | 56 | }; |
b8302363 | 57 | .EE |
e646a1ba | 58 | .in |
fea681da | 59 | .PP |
70d0e5ef MK |
60 | The |
61 | .I semid_ds | |
c84371c6 | 62 | data structure is defined in \fI<sys/sem.h>\fP as follows: |
e646a1ba | 63 | .PP |
70d0e5ef | 64 | .in +4n |
e646a1ba | 65 | .EX |
70d0e5ef | 66 | struct semid_ds { |
45cbde66 | 67 | struct ipc_perm sem_perm; /* Ownership and permissions */ |
70d0e5ef | 68 | time_t sem_otime; /* Last semop time */ |
5fd4345e MK |
69 | time_t sem_ctime; /* Creation time/time of last |
70 | modification via semctl() */ | |
32398a62 | 71 | unsigned long sem_nsems; /* No. of semaphores in set */ |
70d0e5ef | 72 | }; |
b8302363 | 73 | .EE |
e646a1ba | 74 | .in |
a79c3fc0 | 75 | .PP |
1c9b3f5f MK |
76 | The fields of the |
77 | .I semid_ds | |
78 | structure are as follows: | |
79 | .TP 11 | |
80 | .I sem_perm | |
c7d32a9e | 81 | This is an |
1c9b3f5f | 82 | .I ipc_perm |
c7d32a9e | 83 | structure (see below) that specifies the access permissions on the semaphore |
1c9b3f5f MK |
84 | set. |
85 | .TP | |
86 | .I sem_otime | |
87 | Time of last | |
88 | .BR semop (2) | |
89 | system call. | |
90 | .TP | |
91 | .I sem_ctime | |
5fd4345e | 92 | Time of creation of semaphore set or time of last |
6fea5f4f | 93 | .BR semctl () |
5fd4345e MK |
94 | .BR IPCSET , |
95 | .BR SETVAL , | |
96 | or | |
f3061d36 | 97 | .BR SETALL |
5fd4345e | 98 | operation. |
1c9b3f5f MK |
99 | .TP |
100 | .I sem_nsems | |
101 | Number of semaphores in the set. | |
102 | Each semaphore of the set is referenced by a nonnegative integer | |
103 | ranging from | |
104 | .B 0 | |
105 | to | |
106 | .IR sem_nsems\-1 . | |
70d0e5ef MK |
107 | .PP |
108 | The | |
109 | .I ipc_perm | |
548be2a6 | 110 | structure is defined as follows |
70d0e5ef MK |
111 | (the highlighted fields are settable using |
112 | .BR IPC_SET ): | |
113 | .PP | |
70d0e5ef | 114 | .in +4n |
b8302363 | 115 | .EX |
70d0e5ef | 116 | struct ipc_perm { |
b546318a | 117 | key_t __key; /* Key supplied to semget(2) */ |
58413227 MK |
118 | uid_t \fBuid\fP; /* Effective UID of owner */ |
119 | gid_t \fBgid\fP; /* Effective GID of owner */ | |
120 | uid_t cuid; /* Effective UID of creator */ | |
121 | gid_t cgid; /* Effective GID of creator */ | |
70d0e5ef | 122 | unsigned short \fBmode\fP; /* Permissions */ |
b546318a | 123 | unsigned short __seq; /* Sequence number */ |
70d0e5ef | 124 | }; |
b8302363 | 125 | .EE |
e646a1ba | 126 | .in |
70d0e5ef | 127 | .PP |
702f1a76 MK |
128 | The least significant 9 bits of the |
129 | .I mode | |
130 | field of the | |
131 | .I ipc_perm | |
132 | structure define the access permissions for the shared memory segment. | |
133 | The permission bits are as follows: | |
134 | .TS | |
135 | l l. | |
136 | 0400 Read by user | |
137 | 0200 Write by user | |
138 | 0040 Read by group | |
139 | 0020 Write by group | |
140 | 0004 Read by others | |
141 | 0002 Write by others | |
142 | .TE | |
143 | .PP | |
144 | In effect, "write" means "alter" for a semaphore set. | |
145 | Bits 0100, 0010, and 0001 (the execute bits) are unused by the system. | |
146 | .PP | |
70d0e5ef | 147 | Valid values for |
fea681da MK |
148 | .I cmd |
149 | are: | |
0019177e | 150 | .TP |
fea681da | 151 | .B IPC_STAT |
70d0e5ef MK |
152 | Copy information from the kernel data structure associated with |
153 | .I semid | |
154 | into the | |
155 | .I semid_ds | |
156 | structure pointed to by | |
157 | .IR arg.buf . | |
fea681da MK |
158 | The argument |
159 | .I semnum | |
160 | is ignored. | |
70d0e5ef | 161 | The calling process must have read permission on the semaphore set. |
fea681da MK |
162 | .TP |
163 | .B IPC_SET | |
164 | Write the values of some members of the | |
70d0e5ef | 165 | .I semid_ds |
fea681da | 166 | structure pointed to by |
70d0e5ef MK |
167 | .I arg.buf |
168 | to the kernel data structure associated with this semaphore set, | |
169 | updating also its | |
170 | .I sem_ctime | |
fea681da | 171 | member. |
0a33c83e | 172 | .IP |
c13182ef | 173 | The following members of the structure are updated: |
70d0e5ef MK |
174 | .IR sem_perm.uid , |
175 | .IR sem_perm.gid , | |
176 | and (the least significant 9 bits of) | |
177 | .IR sem_perm.mode . | |
0a33c83e | 178 | .IP |
70d0e5ef MK |
179 | The effective UID of the calling process must match the owner |
180 | .RI ( sem_perm.uid ) | |
c13182ef | 181 | or creator |
70d0e5ef MK |
182 | .RI ( sem_perm.cuid ) |
183 | of the semaphore set, or the caller must be privileged. | |
fea681da MK |
184 | The argument |
185 | .I semnum | |
186 | is ignored. | |
187 | .TP | |
188 | .B IPC_RMID | |
70d0e5ef MK |
189 | Immediately remove the semaphore set, |
190 | awakening all processes blocked in | |
0bfa087b | 191 | .BR semop (2) |
70d0e5ef MK |
192 | calls on the set (with an error return and |
193 | .I errno | |
fea681da MK |
194 | set to |
195 | .BR EIDRM ). | |
499d62f2 | 196 | The effective user ID of the calling process must |
540036b2 MK |
197 | match the creator or owner of the semaphore set, |
198 | or the caller must be privileged. | |
fea681da MK |
199 | The argument |
200 | .I semnum | |
201 | is ignored. | |
202 | .TP | |
d064d41a | 203 | .BR IPC_INFO " (Linux\-specific)" |
5fe2d5b7 | 204 | Return information about system-wide semaphore limits and |
24ed820a MK |
205 | parameters in the structure pointed to by |
206 | .IR arg.__buf . | |
207 | This structure is of type | |
208 | .IR seminfo , | |
209 | defined in | |
210 | .I <sys/sem.h> | |
682edefb | 211 | if the |
0daa9e92 | 212 | .B _GNU_SOURCE |
682edefb | 213 | feature test macro is defined: |
e646a1ba | 214 | .IP |
088a639b | 215 | .in +4n |
e646a1ba | 216 | .EX |
24ed820a | 217 | struct seminfo { |
ffc19357 MK |
218 | int semmap; /* Number of entries in semaphore |
219 | map; unused within kernel */ | |
220 | int semmni; /* Maximum number of semaphore sets */ | |
221 | int semmns; /* Maximum number of semaphores in all | |
24ed820a | 222 | semaphore sets */ |
d064d41a | 223 | int semmnu; /* System\-wide maximum number of undo |
ffc19357 MK |
224 | structures; unused within kernel */ |
225 | int semmsl; /* Maximum number of semaphores in a | |
226 | set */ | |
227 | int semopm; /* Maximum number of operations for | |
228 | semop(2) */ | |
229 | int semume; /* Maximum number of undo entries per | |
230 | process; unused within kernel */ | |
231 | int semusz; /* Size of struct sem_undo */ | |
24ed820a | 232 | int semvmx; /* Maximum semaphore value */ |
c13182ef | 233 | int semaem; /* Max. value that can be recorded for |
24ed820a MK |
234 | semaphore adjustment (SEM_UNDO) */ |
235 | }; | |
e646a1ba | 236 | .EE |
088a639b | 237 | .in |
e646a1ba | 238 | .IP |
c13182ef | 239 | The |
24ed820a MK |
240 | .IR semmsl , |
241 | .IR semmns , | |
242 | .IR semopm , | |
243 | and | |
244 | .I semmni | |
245 | settings can be changed via | |
246 | .IR /proc/sys/kernel/sem ; | |
247 | see | |
c13182ef | 248 | .BR proc (5) |
24ed820a MK |
249 | for details. |
250 | .TP | |
8382f16d | 251 | .BR SEM_INFO " (Linux-specific)" |
5fe2d5b7 | 252 | Return a |
24ed820a MK |
253 | .I seminfo |
254 | structure containing the same information as for | |
255 | .BR IPC_INFO , | |
c13182ef | 256 | except that the following fields are returned with information |
24ed820a MK |
257 | about system resources consumed by semaphores: the |
258 | .I semusz | |
c13182ef | 259 | field returns the number of semaphore sets that currently exist |
24ed820a MK |
260 | on the system; and the |
261 | .I semaem | |
c13182ef | 262 | field returns the total number of semaphores in all semaphore sets |
24ed820a MK |
263 | on the system. |
264 | .TP | |
8382f16d | 265 | .BR SEM_STAT " (Linux-specific)" |
5fe2d5b7 | 266 | Return a |
c13182ef | 267 | .I semid_ds |
24ed820a MK |
268 | structure as for |
269 | .BR IPC_STAT . | |
270 | However, the | |
271 | .I semid | |
272 | argument is not a semaphore identifier, but instead an index into | |
273 | the kernel's internal array that maintains information about | |
274 | all semaphore sets on the system. | |
275 | .TP | |
f7246c6d | 276 | .BR SEM_STAT_ANY " (Linux-specific, since Linux 4.17)" |
d2ff4f86 | 277 | Return a |
43ebbd19 YX |
278 | .I semid_ds |
279 | structure as for | |
d2ff4f86 | 280 | .BR SEM_STAT . |
c020b5a2 | 281 | However, |
d2ff4f86 DB |
282 | .I sem_perm.mode |
283 | is not checked for read access for | |
c020b5a2 MK |
284 | .IR semid |
285 | meaning that any user can employ this operation (just as any user may read | |
286 | .IR /proc/sysvipc/sem | |
287 | to obtain the same information). | |
14cbb25e | 288 | .TP |
fea681da MK |
289 | .B GETALL |
290 | Return | |
291 | .B semval | |
70d0e5ef | 292 | (i.e., the current value) |
fea681da | 293 | for all semaphores of the set into |
d6c57ce6 | 294 | .IR arg.array . |
fea681da MK |
295 | The argument |
296 | .I semnum | |
297 | is ignored. | |
70d0e5ef | 298 | The calling process must have read permission on the semaphore set. |
fea681da MK |
299 | .TP |
300 | .B GETNCNT | |
dd7f869f | 301 | Return the |
fea681da | 302 | .B semncnt |
dd7f869f | 303 | value for the |
fea681da MK |
304 | .IR semnum \-th |
305 | semaphore of the set | |
dd7f869f | 306 | (i.e., the number of processes waiting for the semaphore's value to increase). |
70d0e5ef | 307 | The calling process must have read permission on the semaphore set. |
fea681da MK |
308 | .TP |
309 | .B GETPID | |
dd7f869f | 310 | Return the |
fea681da | 311 | .B sempid |
dd7f869f | 312 | value for the |
fea681da | 313 | .IR semnum \-th |
84466c16 MK |
314 | semaphore of the set. |
315 | This is the PID of the process that last performed an operation on | |
316 | that semaphore (but see NOTES). | |
70d0e5ef | 317 | The calling process must have read permission on the semaphore set. |
fea681da MK |
318 | .TP |
319 | .B GETVAL | |
dd7f869f | 320 | Return |
fea681da | 321 | .B semval |
dd7f869f | 322 | (i.e., the semaphore value) for the |
fea681da MK |
323 | .IR semnum \-th |
324 | semaphore of the set. | |
70d0e5ef | 325 | The calling process must have read permission on the semaphore set. |
fea681da MK |
326 | .TP |
327 | .B GETZCNT | |
dd7f869f | 328 | Return the |
fea681da | 329 | .B semzcnt |
dd7f869f | 330 | value for the |
fea681da MK |
331 | .IR semnum \-th |
332 | semaphore of the set | |
dd7f869f | 333 | (i.e., the number of processes waiting for the semaphore value to become 0). |
70d0e5ef | 334 | The calling process must have read permission on the semaphore set. |
fea681da MK |
335 | .TP |
336 | .B SETALL | |
dd7f869f | 337 | Set the |
fea681da | 338 | .B semval |
dd7f869f | 339 | values for all semaphores of the set using |
d6c57ce6 | 340 | .IR arg.array , |
fea681da | 341 | updating also the |
70d0e5ef | 342 | .I sem_ctime |
fea681da | 343 | member of the |
70d0e5ef MK |
344 | .I semid_ds |
345 | structure associated with the set. | |
346 | Undo entries (see | |
347 | .BR semop (2)) | |
348 | are cleared for altered semaphores in all processes. | |
349 | If the changes to semaphore values would permit blocked | |
0bfa087b | 350 | .BR semop (2) |
70d0e5ef | 351 | calls in other processes to proceed, then those processes are woken up. |
fea681da MK |
352 | The argument |
353 | .I semnum | |
354 | is ignored. | |
70d0e5ef MK |
355 | The calling process must have alter (write) permission on |
356 | the semaphore set. | |
fea681da MK |
357 | .TP |
358 | .B SETVAL | |
765a67c3 | 359 | Set the semaphore value |
a1286972 | 360 | .RB ( semval ) |
fea681da | 361 | to |
0daa9e92 | 362 | .I arg.val |
fea681da MK |
363 | for the |
364 | .IR semnum \-th | |
365 | semaphore of the set, updating also the | |
70d0e5ef | 366 | .I sem_ctime |
fea681da | 367 | member of the |
70d0e5ef MK |
368 | .I semid_ds |
369 | structure associated with the set. | |
fea681da | 370 | Undo entries are cleared for altered semaphores in all processes. |
70d0e5ef | 371 | If the changes to semaphore values would permit blocked |
0bfa087b | 372 | .BR semop (2) |
70d0e5ef MK |
373 | calls in other processes to proceed, then those processes are woken up. |
374 | The calling process must have alter permission on the semaphore set. | |
47297adb | 375 | .SH RETURN VALUE |
9862ec0c | 376 | On success, |
540036b2 | 377 | .BR semctl () |
9862ec0c | 378 | returns a nonnegative value depending on |
fea681da MK |
379 | .I cmd |
380 | as follows: | |
0019177e | 381 | .TP |
fea681da MK |
382 | .B GETNCNT |
383 | the value of | |
384 | .BR semncnt . | |
385 | .TP | |
386 | .B GETPID | |
387 | the value of | |
388 | .BR sempid . | |
389 | .TP | |
390 | .B GETVAL | |
391 | the value of | |
392 | .BR semval . | |
393 | .TP | |
394 | .B GETZCNT | |
395 | the value of | |
396 | .BR semzcnt . | |
24ed820a MK |
397 | .TP |
398 | .B IPC_INFO | |
399 | the index of the highest used entry in the | |
400 | kernel's internal array recording information about all | |
401 | semaphore sets. | |
402 | (This information can be used with repeated | |
14cbb25e MK |
403 | .B SEM_STAT |
404 | or | |
405 | .B SEM_STAT_ANY | |
24ed820a MK |
406 | operations to obtain information about all semaphore sets on the system.) |
407 | .TP | |
408 | .B SEM_INFO | |
c5c3137d | 409 | as for |
24ed820a MK |
410 | .BR IPC_INFO . |
411 | .TP | |
412 | .B SEM_STAT | |
413 | the identifier of the semaphore set whose index was given in | |
414 | .IR semid . | |
d2ff4f86 DB |
415 | .TP |
416 | .B SEM_STAT_ANY | |
417 | as for | |
418 | .BR SEM_STAT . | |
dd3568a1 | 419 | .PP |
fea681da MK |
420 | All other |
421 | .I cmd | |
422 | values return 0 on success. | |
9862ec0c MK |
423 | .PP |
424 | On failure, | |
425 | .BR semctl () | |
426 | returns \-1 and sets | |
427 | .I errno | |
428 | to indicate the error. | |
fea681da | 429 | .SH ERRORS |
89b3c6b8 | 430 | .TP |
fea681da MK |
431 | .B EACCES |
432 | The argument | |
433 | .I cmd | |
434 | has one of the values | |
435 | .BR GETALL , | |
436 | .BR GETPID , | |
437 | .BR GETVAL , | |
438 | .BR GETNCNT , | |
439 | .BR GETZCNT , | |
440 | .BR IPC_STAT , | |
441 | .BR SEM_STAT , | |
d2ff4f86 | 442 | .BR SEM_STAT_ANY , |
fea681da MK |
443 | .BR SETALL , |
444 | or | |
445 | .B SETVAL | |
446 | and the calling process does not have the required | |
447 | permissions on the semaphore set and does not have the | |
448 | .B CAP_IPC_OWNER | |
3294109d | 449 | capability in the user namespace that governs its IPC namespace. |
fea681da MK |
450 | .TP |
451 | .B EFAULT | |
452 | The address pointed to by | |
0daa9e92 | 453 | .I arg.buf |
fea681da | 454 | or |
0daa9e92 | 455 | .I arg.array |
fea681da MK |
456 | isn't accessible. |
457 | .TP | |
458 | .B EIDRM | |
459 | The semaphore set was removed. | |
460 | .TP | |
461 | .B EINVAL | |
462 | Invalid value for | |
463 | .I cmd | |
464 | or | |
465 | .IR semid . | |
24ed820a MK |
466 | Or: for a |
467 | .B SEM_STAT | |
c13182ef | 468 | operation, the index value specified in |
24ed820a MK |
469 | .I semid |
470 | referred to an array slot that is currently unused. | |
fea681da MK |
471 | .TP |
472 | .B EPERM | |
473 | The argument | |
474 | .I cmd | |
70d0e5ef | 475 | has the value |
fea681da MK |
476 | .B IPC_SET |
477 | or | |
478 | .B IPC_RMID | |
70d0e5ef | 479 | but the effective user ID of the calling process is not the creator |
fea681da MK |
480 | (as found in |
481 | .IR sem_perm.cuid ) | |
482 | or the owner | |
483 | (as found in | |
484 | .IR sem_perm.uid ) | |
485 | of the semaphore set, | |
486 | and the process does not have the | |
487 | .B CAP_SYS_ADMIN | |
488 | capability. | |
489 | .TP | |
490 | .B ERANGE | |
491 | The argument | |
492 | .I cmd | |
70d0e5ef | 493 | has the value |
fea681da MK |
494 | .B SETALL |
495 | or | |
496 | .B SETVAL | |
497 | and the value to which | |
498 | .B semval | |
70d0e5ef MK |
499 | is to be set (for some semaphore of the set) is less than 0 |
500 | or greater than the implementation limit | |
fea681da | 501 | .BR SEMVMX . |
47297adb | 502 | .SH CONFORMING TO |
175b0eec | 503 | POSIX.1-2001, POSIX.1-2008, SVr4. |
a1d5f77c | 504 | .\" SVr4 documents more error conditions EINVAL and EOVERFLOW. |
efeece04 | 505 | .PP |
26356091 MK |
506 | POSIX.1 specifies the |
507 | .\" POSIX.1-2001, POSIX.1-2008 | |
32398a62 MK |
508 | .I sem_nsems |
509 | field of the | |
510 | .I semid_ds | |
511 | structure as having the type | |
512 | .IR "unsigned\ short" , | |
513 | and the field is so defined on most other systems. | |
514 | It was also so defined on Linux 2.2 and earlier, | |
515 | but, since Linux 2.4, the field has the type | |
516 | .IR "unsigned\ long" . | |
fea681da MK |
517 | .SH NOTES |
518 | The | |
519 | .BR IPC_INFO , | |
d556548b | 520 | .BR SEM_STAT , |
fea681da MK |
521 | and |
522 | .B SEM_INFO | |
24ed820a | 523 | operations are used by the |
81a8f8e7 | 524 | .BR ipcs (1) |
fea681da | 525 | program to provide information on allocated resources. |
282c1a35 MK |
526 | In the future these may modified or moved to a |
527 | .I /proc | |
528 | filesystem interface. | |
dd3568a1 | 529 | .PP |
e3e25559 MK |
530 | Various fields in a \fIstruct semid_ds\fP were typed as |
531 | .I short | |
532 | under Linux 2.2 | |
533 | and have become | |
534 | .I long | |
535 | under Linux 2.4. | |
677f4766 | 536 | To take advantage of this, |
fea681da | 537 | a recompilation under glibc-2.1.91 or later should suffice. |
682edefb | 538 | (The kernel distinguishes old and new calls by an |
0daa9e92 | 539 | .B IPC_64 |
682edefb | 540 | flag in |
fea681da MK |
541 | .IR cmd .) |
542 | .PP | |
70d0e5ef MK |
543 | In some earlier versions of glibc, the |
544 | .I semun | |
26356091 MK |
545 | union was defined in \fI<sys/sem.h>\fP, but POSIX.1 requires |
546 | .\" POSIX.1-2001, POSIX.1-2008 | |
70d0e5ef MK |
547 | that the caller define this union. |
548 | On versions of glibc where this union is \fInot\fP defined, | |
549 | the macro | |
550 | .B _SEM_SEMUN_UNDEFINED | |
c84371c6 | 551 | is defined in \fI<sys/sem.h>\fP. |
70d0e5ef | 552 | .PP |
fea681da | 553 | The following system limit on semaphore sets affects a |
540036b2 | 554 | .BR semctl () |
fea681da | 555 | call: |
89b3c6b8 | 556 | .TP |
fea681da MK |
557 | .B SEMVMX |
558 | Maximum value for | |
559 | .BR semval : | |
560 | implementation dependent (32767). | |
dd3568a1 | 561 | .PP |
27ab91ca | 562 | For greater portability, it is best to always call |
540036b2 | 563 | .BR semctl () |
fea681da | 564 | with four arguments. |
84466c16 MK |
565 | .\" |
566 | .SS The sempid value | |
567 | POSIX.1 defines | |
568 | .I sempid | |
569 | as the "process ID of [the] last operation" on a semaphore, | |
570 | and explicitly notes that this value is set by a successful | |
571 | .BR semop (2) | |
572 | call, with the implication that no other interface affects the | |
573 | .I sempid | |
574 | value. | |
efeece04 | 575 | .PP |
84466c16 MK |
576 | While some implementations conform to the behavior specified in POSIX.1, |
577 | others do not. | |
578 | (The fault here probably lies with POSIX.1 inasmuch as it likely failed | |
579 | to capture the full range of existing implementation behaviors.) | |
580 | Various other implementations | |
581 | .\" At least OpenSolaris (and, one supposes, older Solaris) and Darwin | |
582 | also update | |
583 | .I sempid | |
584 | for the other operations that update the value of a semaphore: the | |
585 | .B SETVAL | |
586 | and | |
587 | .B SETALL | |
588 | operations, as well as the semaphore adjustments performed | |
589 | on process termination as a consequence of the use of the | |
590 | .B SEM_UNDO | |
591 | flag (see | |
592 | .BR semop (2)). | |
efeece04 | 593 | .PP |
84466c16 MK |
594 | Linux also updates |
595 | .I sempid | |
596 | for | |
597 | .BR SETVAL | |
598 | operations and semaphore adjustments. | |
ce160b21 MK |
599 | However, somewhat inconsistently, up to and including Linux 4.5, |
600 | the kernel did not update | |
84466c16 MK |
601 | .I sempid |
602 | for | |
603 | .BR SETALL | |
604 | operations. | |
efcc21c9 MK |
605 | This was rectified |
606 | .\" commit a5f4db877177d2a3d7ae62a7bac3a5a27e083d7f | |
607 | in Linux 4.6. | |
a14af333 | 608 | .SH EXAMPLES |
5d7a1843 MK |
609 | See |
610 | .BR shmop (2). | |
47297adb | 611 | .SH SEE ALSO |
fea681da MK |
612 | .BR ipc (2), |
613 | .BR semget (2), | |
614 | .BR semop (2), | |
f675ea37 | 615 | .BR capabilities (7), |
2c5e151c | 616 | .BR sem_overview (7), |
343cdc5a | 617 | .BR sysvipc (7) |