triptico.com

Un naufragio personal

Sending data in a signal

Craig said on sending additional data or context in a UNIX signal:

"[...] One thing that isn’t as well known is besides sending a signal to a process, you can send some data to it. This can either be an integer or a pointer and uses similar semantics to the known kill and signal handler. [...]"

The key is using sigqueue() instead of signal() and a signal handler like:

void signal_handler(int signum, siginfo_t *siginfo, void *ucontext)
{
    if (signum != SIGUSR1) return;
    if (siginfo->si_code != SI_QUEUE) return;
 
    printf("receiver: Got value %d\n", siginfo->si_int);
}

https://dropbear.xyz/2020/04/29/sending-data-in-a-signal/