SIGQUEUE(2)
π SIGQUEUE(2) β queue a signal to a process (REALTIME) π
okay so bestie, welcome to the System Calls Manual entry for sigqueue β this is the one that lets you yeet a signal plus a whole little value payload at a process, and honestly? iconic behaviour. π
β¨ NAME β¨
sigqueue β queue a signal to a process (REALTIME)
π LIBRARY π
Standard C Library (libc, -lc) β she's built in, no cap, you don't gotta install anything extra π
π«Ά SYNOPSIS π«Ά
#include <signal.h>
int
sigqueue(pid_t pid, int signo, const union sigval value);
πΈ DESCRIPTION πΈ
so like, the sigqueue() system call is the main character here: it takes the signal specified by signo and sends it, bundled with the value specified by value, to the process specified by pid. cute, right?
if signo is zero (that's the null signal, iykyk), then error checking still happens but no signal actually gets sent. think of it as a vibe check for PIDs β you can use the null signal just to check whether a PID is valid. π΅οΈββοΈ
the conditions required for a process to have permission to queue a signal to another process? literally the same as for the kill(2) system call. no new rules, same energy. and yeah, sigqueue() queues a signal to a single process β the one specified by the pid argument. one process, one signal, one delivery. periodt.
sigqueue() returns immediately, fr fr. if the resources were available to queue that signal up, the signal is queued and then sent to the receiving process. π
now this next part is the β¨spicyβ¨ bit, so pay attention bestie:
if the value of pid causes signo to be generated for the sending process, and if signo is not blocked for the calling thread, and if no other thread has signo unblocked or is waiting in a sigwait() system call for signo β then either signo or at least the pending, unblocked signal will be delivered to the calling thread before sigqueue() returns. so you get it handed back to you basically instantly. π
and if any multiple pending signals in the range SIGRTMIN to SIGRTMAX get selected for delivery? it's the lowest numbered one that wins. that's the rule. but the selection order between realtime and non-realtime signals, or between multiple pending non-realtime signals β that is unspecified, so don't come for me, it's not defined. π
okay and here's a cute little FreeBSD extension: you can OR the value of signo with these flags π
π© the flags π©
__SIGQUEUE_TIDβ so with this one, thepidparameter is actually the thread identifier of a thread in the current process, and the specified signal gets queued into the specified thread' queue. yes, target the thread specifically. main character thread energy. π§
π RETURN VALUES π
upon successful completion, the value 0 is returned. slay. otherwise the value -1 is returned and the global variable errno is set to indicate the error β so go check errno, she'll tell you what went wrong. π
π ERRORS π
the sigqueue() system call will fail if:
[EAGAIN]β no resources are available to queue the signal. either the process has already queued{SIGQUEUE_MAX}signals that are still pending at the receiver(s), or a system-wide resource limit has been exceeded. she's full, bestie, the queue is full. π«[EINVAL]β the value of thesignoargument is an invalid or unsupported signal number. that's not a real signal, girl. π«[EPERM]β the process does not have the appropriate privilege to send the signal to the receiving process. permission denied, you don't have the clearance. π[ESRCH]β the processpiddoes not exist. nobody home. π»[ESRCH]β the thread with idpiddoes not exist in the current process. same energy, but the thread is missing this time. π§΅β¨
π SEE ALSO π
kill(2), sigaction(2), sigpending(2), sigsuspend(2), sigtimedwait(2), sigwait(2), sigwaitinfo(2), pause(3), pthread_sigmask(3), siginfo(3) β go read those next, they're all part of the same friend group honestly. π
β STANDARDS β
the sigqueue() system call conforms to IEEE Std 1003.1-2004 (βPOSIX.1β). certified, official, valid. π
π°οΈ HISTORY π°οΈ
support for POSIX realtime signal queue first appeared in FreeBSD 7.0. she's been around a minute. π
β οΈ CAVEATS β οΈ
okay this part is important so listen up:
when usingsigqueueto send signals to a process which might have a different ABI (for instance, one is 32-bit and the other 64-bit), thesival_intmember ofvaluecan be delivered reliably, but thesival_ptrmay be truncated in endian dependent ways and must not be relied on. π±
further, many pointer integrity schemes disallow sending pointers to other processes, and this technique should not be used in programs intended to be portable. so like, don't do it if you want your code to travel. ngl, just don't. π©
β¨ and that's the whole page, bestie β¨ this Debian edition was dated April 21, 2024 β go forth and queue your signals responsibly, ily, mwah ππ¦π
π¦ where this page comes from
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- Copyright (c) 2005 David Xu <davidxu@FreeBSD.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms