SEM_GETVALUE(3P)

πŸ’– SEM_GETVALUE(3P) β€” the POSIX Programmer's Manual page, but make it make sense πŸ’–

okay bestie, welcome to SEM_GETVALUE(3P) from the POSIX Programmer's Manual. pull up a chair, grab a boba, we're gonna read a manpage together πŸ§‹βœ¨

🌸 PROLOG 🌸

okay so real talk first: this page is part of the POSIX Programmer's Manual. the Linux implementation of this interface may differ (so like, go check the corresponding Linux manual page for the tea on Linux behavior), or honestly the interface may not even be implemented on Linux at all. πŸ’€ no cap, just how it is.


✨ NAME ✨

sem_getvalue β€” get the value of a semaphore πŸ‘‘


πŸŽ€ SYNOPSIS πŸŽ€

#include <semaphore.h>

int sem_getvalue(sem_t *restrict sem, int *restrict sval);

πŸ¦‹ DESCRIPTION πŸ¦‹

so here's the vibe. the sem_getvalue() function shall update the location referenced by the sval argument to have the value of the semaphore referenced by sem β€” and it does this without affecting the state of the semaphore. like, it's a look, not a touch. no side effects, we're just peeking πŸ‘€

here's the catch tho, and it's giving "time is a construct": the updated value represents an actual semaphore value that occurred at some unspecified time during the call, but it need not be the actual value of the semaphore when it is returned to the calling process. so like… it was true at some point. iconic. unreliable narrator energy fr fr 😭

and if sem is locked, then the object that sval points to shall either be set to zero, or be set to a negative number whose absolute value represents the number of processes waiting for the semaphore at some unspecified time during the call. two valid answers, no in-between drama. πŸ’…


⭐ RETURN VALUE ⭐

  • on a successful completion, sem_getvalue() shall return a value of zero. slay. 🫢
  • otherwise it shall return a value of -1 and set errno to indicate the error. not slay. 😭

πŸ’… ERRORS πŸ’…

the sem_getvalue() function may fail if:

  • EINVAL β€” the sem argument does not refer to a valid semaphore.
heads up bestie: the following sections are informative. (translation: they're vibes, not requirements.)

🌈 EXAMPLES 🌈

None. β€” yes literally, there are none. the void. nothing. we move. πŸ™ˆ


πŸ’œ APPLICATION USAGE πŸ’œ

None. β€” again, nothing here. short king section. πŸ‘‘


🧚 RATIONALE 🧚

None. β€” nope, they didn't give us one. mystery behavior, and honestly? we respect it. ✨


πŸ“ FUTURE DIRECTIONS πŸ“

None. β€” no future plans announced. it's just gonna keep on doing its thing. periodt.


πŸ”₯ SEE ALSO πŸ”₯

  • semctl()
  • semget()
  • semop()
  • sem_post()
  • sem_timedwait()
  • sem_trywait()

also the Base Definitions volume of POSIX.1‐2017, <semaphore.h> πŸ“š


okay legal moment, stay with me, this matters:

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. (so if we ever disagree, they win, no debate 🫑) 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 was SEM_GETVALUE(3P) from IEEE/The Open Group, 2017 β€” go forth and read your semaphores without fear, you absolute main character πŸ¦‹πŸ‘‘βœ¨

πŸ“¦ where this page comes from