本文介绍了如何触发SIGUSR1和SIGUSR2?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我越来越有信号熟悉C语言我想不出有什么样的信号 SIGUSR1
和 SIGUSR2
是,我怎么能触发它们。任何人都可以请解释一下?
I'm getting acquainted with signals in C. I can't figure out what kind of signals SIGUSR1
and SIGUSR2
are and how can I trigger them. Can anyone please explain it to me?
推荐答案
它们的用户定义的信号,使它们不被任何特定的动作触发。你可以明确地编程方式发送它们:
They are user-defined signals, so they aren't triggered by any particular action. You can explicitly send them programmatically:
#include <signal.h>
kill(pid, SIGUSR1);
其中, PID
是接收进程的进程ID。在接收端,你能为他们注册一个信号处理程序:
where pid
is the process id of the receiving process. At the receiving end, you can register a signal handler for them:
#include <signal.h>
void my_handler(int signum)
{
if (signum == SIGUSR1)
{
printf("Received SIGUSR1!\n");
}
}
signal(SIGUSR1, my_handler);
这篇关于如何触发SIGUSR1和SIGUSR2?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!