SIGWAIT(3POSIX)
π¦ SIGWAIT(3POSIX) π¦ β wait for queued signals
okay bestie, so this page is SIGWAIT(3POSIX) from the POSIX Programmer's Manual, and we're about to make signal-waiting make sense. pull up a chair π
β¨ PROLOG β¨
so like, heads up before we even start:
- 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 at all. iykyk π
πΈ NAME πΈ
sigwait β wait for queued signals. that's it, that's the whole vibe.
π SYNOPSIS π
#include <signal.h>
int sigwait(const sigset_t *restrict set, int *restrict sig);
π DESCRIPTION π
okay so here's the tea. the sigwait() function shall select a pending signal from set, atomically clear it from the system's set of pending signals, and return that signal number in the location referenced by sig. iconic behavior, truly.
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. ngl, that part is a little "depends on the vibes of your implementation."
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. so the rest just chill in line, no cap.
If no signal in set is pending at the time of the call, the thread shall be suspended until one or more becomes pending. nap time until something actually happens π΄
The signals defined bysetshall have been blocked at the time of the call tosigwait(); otherwise, the behavior is undefined. do NOT skip this step bestie, it's the whole plot twist.
The effect of sigwait() on the signal actions for the signals in set is unspecified.
Now, the multi-thread drama π:
- If more than one thread is using
sigwait()to wait for the same signal, no more than one of these threads shall return fromsigwait()with the signal number. - 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 fromsigwait(). - If the signal is generated for a specific thread, as by
pthread_kill(), only that thread shall return. main character energy, honestly.
And for the realtime girlies β¨: 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.
π«Ά 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. slay either way, but zero is the good ending.
π₯ ERRORS π₯
The sigwait() function may fail if:
EINVALβ thesetargument contains an invalid or unsupported signal number.
The following sections are informative.
π EXAMPLES π
None. yes bestie, literally none, we're working with nothing here π
π APPLICATION USAGE π
None. also nothing. the void stares back π
π 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. three compliments in one sentence, we love to see it.
However, 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. the future is, apparently, not giving us anything new here.
π§ 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!! brought to you by IEEE/The Open Group, 2017 β mwah, go forth and block your signals before you sigwait() π
β¨
π¦ where this page comes from
- debian bookworm: manpages-posix-dev 2017a-2 Β· Other
- debian trixie: manpages-posix-dev 2017a-2 Β· Other
- ubuntu jammy: manpages-posix-dev 2017a-2 Β· Other
- ubuntu noble: manpages-posix-dev 2017a-2 Β· Other
- ubuntu resolute: manpages-posix-dev 2017a-2build1 Β· Other
- ubuntu stonking: manpages-posix-dev 2017a-2.1 Β· Other
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms