semaphore.h(0P)
π«Ά PROLOG π«Ά
okay bestie, real talk before we get into it π this page is part of the POSIX Programmer's Manual. that's the vibe. but heads up β the Linux implementation of this interface may be different (so go check the corresponding Linux manual page for the deets on Linux behavior, fr), or honestly it might not even be implemented on Linux at all. π so like, don't come for me if it's not there.
β¨ NAME β¨
semaphore.h β semaphores π
(and yes bestie, this is the semaphore.h(0P) page, we're in the POSIX Programmer's Manual, iykyk π)
πΈ SYNOPSIS πΈ
#include <semaphore.h>
π DESCRIPTION π
so the <semaphore.h> header is gonna define the sem_t type, which is the whole main character of semaphore operations β¨. lowkey important detail: the semaphore may be implemented using a file descriptor, and if that's the case, applications can open up at least a total of {OPEN_MAX} files and semaphores. like, combined. periodt. π
The <semaphore.h> header shall define the symbolic constant SEM_FAILED, and it shall have the type sem_t *.
The following shall be declared as functions and may also be defined as macros. Function prototypes shall be provided. π«‘
int sem_close(sem_t *);
int sem_destroy(sem_t *);
int sem_getvalue(sem_t *restrict, int *restrict);
int sem_init(sem_t *, int, unsigned);
sem_t *sem_open(const char *, int, ...);
int sem_post(sem_t *);
int sem_timedwait(sem_t *restrict, const struct timespec *restrict);
int sem_trywait(sem_t *);
int sem_unlink(const char *);
int sem_wait(sem_t *);
ngl, including the <semaphore.h> header may make symbols defined in the <fcntl.h> and <time.h> headers visible too. so like, surprise guests at the function party π not me finding that out the hard way π.
The following sections are informative. (aka: the chill sections, not the law sections, bestie π§)
π¦ APPLICATION USAGE π¦
None. π literally nothing. we love a low-effort icon.
π RATIONALE π
None. again β nothing. the silence is the statement. β¨
π FUTURE DIRECTIONS π
None. slay, no notes, we're not going anywhere. π
π SEE ALSO π
go read these bestie, they're the friend group:
<fcntl.h><sys_types.h><time.h>
The System Interfaces volume of POSIX.1β2017, and these absolute icons:
sem_close()sem_destroy()sem_getvalue()sem_init()sem_open()sem_post()sem_timedwait()sem_trywait()sem_unlink()
π 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.
π¨ okay so real talk: if there's 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. like, it's the final boss, the actual authority, no cap. 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 was brought to you by IEEE/The Open Group, dated 2017, on the semaphore.h(0P) page π mwah, go forth and 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