sys_sem.h(0P)
β¨ PROLOG β¨
ok so real talk first π this manual page is part of the POSIX Programmer's Manual. the Linux implementation of this interface may differ (so pls go check the corresponding Linux manual page for the deets on how Linux actually does it), or honestly the interface may not even be implemented on Linux at all. so like, vibe check before you commit, bestie.
π NAME π
sys/sem.h β the XSI semaphore facility. yes we're doing semaphores today, and yes it's giving very "systems programming final boss" energy π
πΈ SYNOPSIS πΈ
#include <sys/sem.h>
π DESCRIPTION π
ok so here's the whole tea. the <sys/sem.h> header is gonna define a symbolic constant for you to use as a semaphore operation flag, and it's this one:
SEM_UNDOβ set up an adjust on exit entry. (yes it undoes stuff for you when you dip, iconic behaviour honestly)
then the header also defines these symbolic constants for you to use as commands for the semctl() function:
GETNCNTβ getsemncnt.GETPIDβ getsempid.GETVALβ getsemval.GETALLβ get all cases ofsemval.GETZCNTβ getsemzcnt.SETVALβ setsemval.SETALLβ set all cases ofsemval.
then the <sys/sem.h> header defines the semid_ds structure, and it shall include these members:
struct ipc_perm sem_perm Operation permission structure.
unsigned short sem_nsems Number of semaphores in set.
time_t sem_otime Last semop() time.
time_t sem_ctime Last time changed by semctl().
the <sys/sem.h> header also defines the pid_t, size_t, and time_t types, and those are described over in <sys/types.h> π¦
a semaphore is represented by an anonymous structure, and that one includes these members:
unsigned short semval Semaphore value.
pid_t sempid Process ID of last operation.
unsigned short semncnt Number of processes waiting for semval
to become greater than current value.
unsigned short semzcnt Number of processes waiting for semval
to become 0.
and then <sys/sem.h> defines the sembuf structure, which includes these members:
unsigned short sem_num Semaphore number.
short sem_op Semaphore operation.
short sem_flg Operation flags.
the following shall be declared as functions and may also be defined as macros β function prototypes shall be provided, no skipping:
int semctl(int, int, int, ...);
int semget(key_t, int, int);
int semop(int, struct sembuf *, size_t);
and on top of all that, the <sys/sem.h> header shall include the <sys/ipc.h> header. package deal, no a la carte π«Ά
heads up: the following sections are informative. so like, they're the commentary track, not the requirements.
π APPLICATION USAGE π
None. literally none. we love a low-effort section π
β RATIONALE β
None. also none. the restraint? unmatched.
π¦ FUTURE DIRECTIONS π¦
None. nothing coming, nothing to prepare for, we stay present π
π₯ SEE ALSO π₯
<sys_ipc.h><sys_types.h>
and from the System Interfaces volume of POSIX.1β2017: semctl(), semget(), semop(). go read those next, bestie, this header is only half the story β¨
π 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 .
ok that's the whole page, mwah π this was IEEE/The Open Group, 2017, and we were reading sys_sem.h(0P) the whole time. semaphores understood, bestie unlocked, periodt.
π¦ 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