[英]Sending information with a Signal in Linux
When sending a signal from one process to another, I also want to send a value of type long . 当从一个进程向另一个进程发送信号时,我还想发送long类型的值。 Is that possible?
那可能吗? I am using SIGUSR1.
我正在使用SIGUSR1。
Sure you can, but you'll have to send it with sigqueue(2)
instead of kill(2)
. 当然可以,但你必须用
sigqueue(2)
而不是kill(2)
发送它。 And you can send an int
or a sival_ptr
. 你可以发送一个
int
或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 使用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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.