SIGWAIT(3P)
π¦ SIGWAIT(3P) β POSIX Programmer's Manual π¦
okay bestie, sit down, hydrate, we're doing signals today π
β οΈ PROLOG β οΈ
Heads up fr fr: this manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ β so go consult the corresponding Linux manual page for the deets on Linux behavior. Or, plot twist, the interface may not even be implemented on Linux at all. π So check before you ship, okay?
β¨ NAME β¨
sigwait β wait for queued signals π
πΈ SYNOPSIS πΈ
#include <signal.h>
int sigwait(const sigset_t *restrict set, int *restrict sig);
π DESCRIPTION π
okay so here's the whole vibe. The sigwait() function shall:
- select a pending signal from
set - atomically clear it from the system's set of pending signals
- return that signal number in the location referenced by
sig
Now. If, prior to the call to sigwait(), there are multiple pending instances of a single signal number, it is implementation-defined whether upon successful return there are any remaining pending signals for that signal number. iykyk β it's giving "your mileage may vary" π«
If the implementation supports queued signals and there are multiple signals queued for the signal number selected, the first such queued signal shall cause a return from sigwait() and the remainder shall remain queued. β¨ queue discipline, we love to see it β¨
If no signal in set is pending at the time of the call, the thread shall be suspended until one or more becomes pending. Not me just... sitting here... waiting... π΄
The signals defined by set shall have been blocked at the time of the call to sigwait(); otherwise, the behavior is undefined. π¨
The effect of sigwait() on the signal actions for the signals in set is unspecified. π
If more than one thread is using sigwait() to wait for the same signal, no more than one of these threads shall return from sigwait() with the signal number. One winner, no ties, periodt. π
If more than a single thread is blocked in sigwait() for a signal when that signal is generated for the process, it is unspecified which of the waiting threads returns from sigwait(). Literally a mystery box. π
But! If the signal is generated for a specific thread, as by pthread_kill(), only that thread shall return. Main character energy, no line-cutting allowed. π
Should any of the multiple pending signals in the range SIGRTMIN to SIGRTMAX be selected, it shall be the lowest numbered one. π
The selection order between realtime and non-realtime signals, or between multiple pending non-realtime signals, is unspecified. We simply do not know. π€·ββοΈ
π RETURN VALUE π
Upon successful completion, sigwait() shall store the signal number of the received signal at the location referenced by sig and return zero. β¨
Otherwise, an error number shall be returned to indicate the error. π
π ERRORS π
The sigwait() function may fail if:
EINVALβ Thesetargument contains an invalid or unsupported signal number. π ββοΈ
The following sections are informative.
π§ EXAMPLES π§
None.
π APPLICATION USAGE π
None.
π₯ RATIONALE π₯
To provide a convenient way for a thread to wait for a signal, this volume of POSIX.1β2017 provides the sigwait() function. For most cases where a thread has to wait for a signal, the sigwait() function should be quite convenient, efficient, and adequate. slay π
However β and this is the tea β β requests were made for a lower-level primitive than sigwait() and for semaphores that could be used by threads. After some consideration, threads were allowed to use semaphores and sem_post() was defined to be async-signal-safe. π«Ά
In summary, when it is necessary for code run in response to an asynchronous signal to notify a thread, sigwait() should be used to handle the signal. Alternatively, if the implementation provides semaphores, they also can be used, either following sigwait() or from within a signal handling routine previously registered with sigaction(). β¨
π FUTURE DIRECTIONS π
None.
π SEE ALSO π
Section 2.4, Signal Concepts, Section 2.8.1, Realtime Signals, pause(), pthread_sigmask(), sigaction(), sigpending(), sigsuspend(), sigtimedwait()
The Base Definitions volume of POSIX.1β2017, <signal.h>, <time.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 the lovely people at IEEE / The Open Group, 2017 β that's the SIGWAIT(3P) energy, no cap, go block those signals before you call it fr fr π«Άβ¨
π¦ 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