SEMCTL(3P)
π SEMCTL(3P) π β the POSIX Programmer's Manual one, bestie
okay so before we even get into it: this is semctl, from the POSIX Programmer's Manual. Heads up though β the Linux implementation of this interface may differ (so like, go check the corresponding Linux manual page for the deets on Linux behavior), or honestly the interface might just not be implemented on Linux at all. π iykyk.
β¨ PROLOG β¨
This manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ β consult the corresponding Linux manual page for details of Linux behavior β or the interface may not be implemented on Linux. π
π NAME π
semctl β XSI semaphore control operations. she does semaphore control. that's the whole vibe. π¦
πΈ SYNOPSIS πΈ
#include <sys/sem.h>
int semctl(int semid, int semnum, int cmd, ...);
the ... is literally doing so much work here, we'll get to that. π«Ά
π DESCRIPTION π
The semctl() function operates on XSI semaphores (peep the Base Definitions volume of POSIX.1β2017, Section 4.17, Semaphore). It is unspecified whether this function interoperates with the realtime interprocess communication facilities defined in Section 2.8, Realtime. so like... maybe? maybe not? nobody's promising anything. π
The semctl() function provides a variety of semaphore control operations as specified by cmd. The fourth argument is optional and depends upon the operation requested. If required, it is of type union semun, which the application shall explicitly declare:
union semun {
int val;
struct semid_ds *buf;
unsigned short *array;
} arg;
Each operation shall be performed atomically. no half-sends. periodt. π
The following semaphore control operations as specified by cmd are executed with respect to the semaphore specified by semid and semnum. The level of permission required for each operation is shown with each command; see Section 2.7, XSI Interprocess Communication. The symbolic names for the values of cmd are defined in the <sys/sem.h> header:
GETVALβ Return the value ofsemval; see<sys/sem.h>. Requires read permission. πSETVALβ Set the value ofsemvaltoarg.val, whereargis the value of the fourth argument tosemctl(). When this command is successfully executed, thesemadjvalue corresponding to the specified semaphore in all processes is cleared. Also, thesem_ctimetimestamp shall be set to the current time, as described in Section 2.7.1, IPC General Description. Requires alter permission; see Section 2.7, XSI Interprocess Communication.GETPIDβ Return the value ofsempid. Requires read permission.GETNCNTβ Return the value ofsemncnt. Requires read permission.GETZCNTβ Return the value ofsemzcnt. Requires read permission.
The following values of cmd operate on each semval in the set of semaphores β like, the whole squad, not just one:
GETALLβ Return the value ofsemvalfor each semaphore in the semaphore set and place into the array pointed to byarg.array, whereargis the fourth argument tosemctl(). Requires read permission.SETALLβ Set the value ofsemvalfor each semaphore in the semaphore set according to the array pointed to byarg.array, whereargis the fourth argument tosemctl(). When this command is successfully executed, thesemadjvalues corresponding to each specified semaphore in all processes are cleared. Also, thesem_ctimetimestamp shall be set to the current time, as described in Section 2.7.1, IPC General Description. Requires alter permission.
The following values of cmd are also available β the admin-girlie section π
:
IPC_STATβ Place the current value of each member of thesemid_dsdata structure associated withsemidinto the structure pointed to byarg.buf, whereargis the fourth argument tosemctl(). The contents of this structure are defined in<sys/sem.h>. Requires read permission.IPC_SETβ Set the value of the following members of thesemid_dsdata structure associated withsemidto the corresponding value found in the structure pointed to byarg.buf, whereargis the fourth argument tosemctl():sem_perm.uidsem_perm.gidsem_perm.mode
The mode bits specified in Section 2.7.1, IPC General Description are copied into the corresponding bits of the sem_perm.mode associated with semid. The stored values of any other bits are unspecified. The sem_ctime timestamp shall be set to the current time, as described in Section 2.7.1, IPC General Description.
This command can only be executed by a process that has an effective user ID equal to either that of a process with appropriate privileges or to the value of sem_perm.cuid or sem_perm.uid in the semid_ds data structure associated with semid. so like, it's giving permission slip energy, no random girlies allowed. π«
IPC_RMIDβ Remove the semaphore identifier specified bysemidfrom the system and destroy the set of semaphores andsemid_dsdata structure associated with it. This command can only be executed by a process that has an effective user ID equal to either that of a process with appropriate privileges or to the value ofsem_perm.cuidorsem_perm.uidin thesemid_dsdata structure associated withsemid.
β οΈ bestie listen:IPC_RMIDliterally destroys the whole semaphore set. it's the delete-everything button. and bothIPC_SETandIPC_RMIDare locked to the effective user ID of a process with appropriate privileges, or matchingsem_perm.cuid/sem_perm.uid. no cap.
π RETURN VALUE π
If successful, the value returned by semctl() depends on cmd as follows:
GETVALβ The value ofsemval.GETPIDβ The value ofsempid.GETNCNTβ The value ofsemncnt.GETZCNTβ The value ofsemzcnt.- All others β
0.
Otherwise, semctl() shall return -1 and set errno to indicate the error. it's giving rejection arc. π
π ERRORS π
The semctl() function shall fail if:
EACCESβ Operation permission is denied to the calling process; see Section 2.7, XSI Interprocess Communication.EINVALβ The value ofsemidis not a valid semaphore identifier, or the value ofsemnumis less than0or greater than or equal tosem_nsems, or the value ofcmdis not a valid command.EPERMβ The argumentcmdis equal toIPC_RMIDorIPC_SETand the effective user ID of the calling process is not equal to that of a process with appropriate privileges and it is not equal to the value ofsem_perm.cuidorsem_perm.uidin the data structure associated withsemid.ERANGEβ The argumentcmdis equal toSETVALorSETALLand the value to whichsemvalis to be set is greater than the system-imposed maximum. too much. overflowing. she can't hold all that. π
The following sections are informative. (yes that's a real thing the original says, keeping it.)
π EXAMPLES π
Refer to semop(). that's it. that's the example. go read the other one bestie. π«Ά
π§ APPLICATION USAGE π§
The fourth parameter in the SYNOPSIS section is now specified as "..." in order to avoid a clash with the ISO C standard when referring to the union semun (as defined in Issue 3) and for backwards-compatibility. so the ... isn't her being mysterious, it's legal reasons. iconic of her honestly. β¨
The POSIX Realtime Extension defines alternative interfaces for interprocess communication. Application developers who need to use IPC should design their applications so that modules using the IPC routines described in Section 2.7, XSI Interprocess Communication can be easily modified to use the alternative interfaces. future-proofing, we love to see it. π
π RATIONALE π
None.
like... none. nothing. silence. the audacity. π
β FUTURE DIRECTIONS β
None.
π¦ SEE ALSO π¦
Section 2.7, XSI Interprocess Communication, Section 2.8, Realtime, semget(), semop(), sem_close(), sem_destroy(), sem_getvalue(), sem_init(), sem_open(), sem_post(), sem_trywait(), sem_unlink()
The Base Definitions volume of POSIX.1β2017, Section 4.17, Semaphore, <sys_sem.h>
πΈ COPYRIGHT πΈ
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html .
Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .
and that's the whole page bestie!! π this one came from IEEE/The Open Group, dated 2017, and she's page SEMCTL(3P) β slay, mwah, go semaphore responsibly. πβ¨π¦
π¦ where this page comes from
- alpine 3.22: man-pages-posix 2017a-r0 Β· custom
- alpine 3.23: man-pages-posix 2017a-r0 Β· custom
- alpine 3.24: man-pages-posix 2017a-r0 Β· custom
- arch rolling: man-pages 6.19-1
- arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages-posix 2017a
- opensuse-leap 16.0: man-pages-posix 2017a-160000.4.1 Β· SUSE-IEEE
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms