sys_sem.h(7POSIX)

πŸŽ€ sys_sem.h β€” the XSI semaphore facility, bestie edition πŸŽ€

okay so before we even get into it: this is a page 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 actual Linux tea β˜•), or the interface might not even be implemented on Linux at all. πŸ™ˆ


✨ 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 🌸

sys/sem.h β€” the XSI semaphore facility. yeah. semaphores. the whole vibe. πŸ’…


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <sys/sem.h>

that's it. that's the whole synopsis. one include. iconic behavior honestly. ✨


πŸ’– DESCRIPTION πŸ’–

okay so the <sys/sem.h> header shall define a bunch of stuff, and we're gonna go through literally all of it, no skipping, because every single one matters. 🫢

🌈 the semaphore operation flag

The <sys/sem.h> header shall define this symbolic constant for use as a semaphore operation flag:

  • SEM_UNDO β€” set up adjust on exit entry.

⭐ the semctl() command constants

The <sys/sem.h> header shall define these symbolic constants for use as commands for the semctl() function:

  • GETNCNT β€” get semncnt.
  • GETPID β€” get sempid.
  • GETVAL β€” get semval.
  • GETALL β€” get all cases of semval.
  • GETZCNT β€” get semzcnt.
  • SETVAL β€” set semval.
  • SETALL β€” set all cases of semval.

seven of them. count 'em. slay. πŸ”₯

πŸ“ the semid_ds structure

The <sys/sem.h> header shall define the semid_ds structure, and bestie 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 pid_t, size_t, and time_t types

The <sys/sem.h> header shall define the pid_t, size_t, and time_t types as described in <sys/types.h>.

πŸ’œ the anonymous semaphore structure

A semaphore shall be represented by an anonymous structure, which shall include the following 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.

not me getting emotional over semzcnt waiting for semval to become 0 😭 the dedication. the loyalty.

πŸ‘‘ the sembuf structure

The <sys/sem.h> header shall define the sembuf structure, which shall include the following members:

unsigned short  sem_num   Semaphore number.
short           sem_op    Semaphore operation.
short           sem_flg   Operation flags.

🌟 the functions

The following shall be declared as functions and may also be defined as macros. Function prototypes shall be provided.

int   semctl(int, int, int, ...);
int   semget(key_t, int, int);
int   semop(int, struct sembuf *, size_t);

three little icons. main character energy fr fr. πŸ’…

πŸŽ€ and one more include

In addition, the <sys/sem.h> header shall include the <sys/ipc.h> header.

psst β€” the following sections are informative. iykyk.

πŸ’… APPLICATION USAGE πŸ’…

None.

(genuinely nothing. the void. the silence. we love a minimal queen. ✨)


🌸 RATIONALE 🌸

None.


πŸ¦‹ FUTURE DIRECTIONS πŸ¦‹

None.


⭐ SEE ALSO ⭐

  • <sys_ipc.h>, <sys_types.h>
  • The System Interfaces volume of POSIX.1‐2017, semctl(), semget(), semop()

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 .


okay that's the whole page bestie, go forth and semaphore responsibly 🫢✨

mwah πŸ’‹ this lil rewrite brought to you by IEEE/The Open Group, dated 2017 β€” the original sys_sem.h(7POSIX) era, and honestly? they ate. πŸŒˆπŸ‘‘