SIGTIMEDWAIT(2)
β¨ SIGTIMEDWAIT β¨ (that's the sigtimedwait(2) page bestie, section 2, System Calls Manual) π
πΈ NAME πΈ
sigtimedwait, sigwaitinfo β wait for queued signals (REALTIME) π
π¦ LIBRARY π¦
Standard C Library (libc, -lc) π
β SYNOPSIS β
#include <signal.h>
int
sigtimedwait(const sigset_t *restrict set, siginfo_t *restrict info,
const struct timespec *restrict timeout);
int
sigwaitinfo(const sigset_t * restrict set, siginfo_t * restrict info);
okay so this is the whole vibe right here β you include <signal.h> and then you've got two lil besties doing basically the same job, one of them just has a timer. π°οΈβ¨
π DESCRIPTION π
So like, sigtimedwait() is literally sigwaitinfo() but with β¨patienceβ¨ β it's equivalent to sigwaitinfo() except that if none of the signals specified by set are pending, sigtimedwait() waits for the time interval specified in the timespec structure referenced by timeout. π«Ά
If the timespec structure pointed to by timeout is zero-valued and none of the signals specified by set are pending, then sigtimedwait() returns immediately with an error. no waiting, no vibes, just β¨noβ¨.
β οΈ Iftimeoutis theNULLpointer, the behavior is unspecified. do not do this. that's not main character energy, that's chaos energy. π
CLOCK_MONOTONIC clock is used to measure the time interval specified by the timeout argument. no cap. β±οΈ
Now sigwaitinfo() β the way that this one selects the pending signal from the set specified by set?? iconic. π Should any of 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 β so don't come for me asking which one wins, the manpage said what it said. π
If no signal in set is pending at the time of the call, the calling thread is suspended until one or more signals in set become pending or until it is interrupted by an unblocked, caught signal. it's giving "waiting for your text back" energy ngl π
sigwaitinfo() is equivalent to the sigwait() system call if the info argument is NULL. π―
If the info argument is non-NULL, sigwaitinfo() is equivalent to sigwait(), except that:
- the selected signal number shall be stored in the
si_signomember β¨ - the cause of the signal shall be stored in the
si_codemember β¨
Besides this, the sigwaitinfo() and sigtimedwait() system calls may return EINTR if interrupted by signal, which is not allowed for the sigwait() function. π note the difference bestie, it matters.
If any value is queued to the selected signal, the first such queued value is dequeued and, if the info argument is non-NULL, the value is stored in the si_value member of info. π
The system resource used to queue the signal is released and returned to the system for other use. (recycling! sustainable queen π)
If no value is queued, the content of the si_value member is zero-valued. 0οΈβ£
If no further signals are queued for the selected signal, the pending indication for that signal is reset. β
π₯ RETURN VALUES π₯
Upon successful completion β that is, one of the signals specified by set is pending or is generated β sigwaitinfo() and sigtimedwait() return the selected signal number. π
Otherwise, the functions return a value of -1 and set the global variable errno to indicate the error. π that's the sad path, we don't love her but we respect her.
π ERRORS π
The sigtimedwait() system call will fail if:
[EAGAIN]β No signal specified bysetwas generated within the specifiedtimeoutperiod. (you waited, nothing came, ghosted fr fr π»)
The sigtimedwait() and sigwaitinfo() system calls fail if:
[EINTR]β The wait was interrupted by an unblocked, caught signal. (jumpscare interrupt π€)
The sigtimedwait() system call may also fail if:
[EINVAL]β Thetimeoutargument specified atv_nsecvalue less than zero or greater than or equal to 1000 million. π Important caveat coming: the kernel only checks for this error if no signal is pending insetand it is necessary to wait. so like, if there's already a signal sitting there ready, it is not gonna bother checking. iykyk.
π§ SEE ALSO π§
sigaction(2)sigpending(2)sigqueue(2)sigsuspend(2)sigwait(2)pause(3)pthread_sigmask(3)siginfo(3)
all the siblings, all iconic, go read them too ππ
π STANDARDS π
The sigtimedwait() and sigwaitinfo() system calls conform to ISO/IEC 9945-1:1996 (βPOSIX.1β). certified, validated, slaying. π
and that's the whole page bestie!! this one came from the Debian crew, dated September 27, 2012, sitting pretty in section 2 of the System Calls Manual. π go handle your signals responsibly, mwah π«Άβ¨
π¦ where this page comes from
- debian bookworm: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- debian trixie: freebsd-manpages 12.2-2 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu jammy: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu noble: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu questing: freebsd-manpages 12.2-2
- ubuntu resolute: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu stonking: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- Copyright (c) 2005 David Xu <davidxu@FreeBSD.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms