追赶自己的处理程序内部信号 [英] Catching signal inside its own handler
本文介绍了追赶自己的处理程序内部信号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
#include<stdio.h>
#include<signal.h>
void handler(int signo)
{
printf("Into handler\n");
while(1);
}
int main()
{
struct sigaction act;
act.sa_handler = handler;
act.sa_flags = 0;
sigemptyset(& act.sa_mask);
sigaction(SIGINT, &act, NULL);
while(1);
return 0;
}
捕后的 KeyboardInterrupt 一次,当我再次preSSCTRL + C,SIGINT不处理...
我意愿的进入处理程序应每我的时间打印preSSCTRL + C
After catching the KeyboardInterrupt once, when I press "Ctrl+C" again, SIGINT is not handled... I intend that "Into handler" should be printed each time I press "Ctrl+C".
我要赶在里面SIGINTSIGINT处理程序()本身..
推荐答案
您需要设置SA_NODEFER上sa_mask赶上相同的信号作为一个你当前正在处理:
You need to set SA_NODEFER on sa_mask to catch the same signal as the one you're currently handling:
SA_NODEFER:从自己的信号处理程序中接收不要prevent信号。 SA_NOMASK是这个标志一个过时的,不规范的代名词。
SA_NODEFER: Do not prevent the signal from being received from within its own signal handler. SA_NOMASK is an obsolete, non-standard synonym for this flag.
这篇关于追赶自己的处理程序内部信号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文