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