SIGQUEUE(2)

πŸ“¦ version 15.1, in freebsd 14.5, freebsd 15.1

πŸ’Œ 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, the pid parameter 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 the signo argument 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 process pid does not exist. nobody home. πŸ‘»
  • [ESRCH] β€” the thread with id pid does 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 using sigqueue to send signals to a process which might have a different ABI (for instance, one is 32-bit and the other 64-bit), the sival_int member of value can be delivered reliably, but the sival_ptr may 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