When sending a signal from one process to another, I also want to send a value of type long. Is that possible? I am using SIGUSR1.
Sure you can, but you'll have to send it with sigqueue(2)
instead of kill(2)
. And you can send an int
or a sival_ptr
.
union sigval {
int sival_int;
void *sival_ptr;
};
Establish the handler
struct sigaction sa;
sigemptyset(&sa.sa_mask);
sa.sa_sigaction = handler;
sa.sa_flags = SA_SIGINFO; /* Important. */
sigaction(SIGUSR1, &sa, NULL);
The handler for a signal established using SA_SIGINFO
static void
handler(int sig, siginfo_t *si, void *ucontext)
{
si->si_value; /* This is what you're looking for. */
}
Sending an integer
union sigval sv;
sv.sival_int = 42;
sigqueue(pid, SIGUSR1, sv);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With