当前位置: 技术问答>linux和unix
为何信号处理没有及时被处理呢?
来源: 互联网 发布时间:2017-03-13
本文导语: #include #include #include void Printf(int signo) { printf("received sigintn"); } void ALrm(int signo) { printf("received Alrm"); } int main() { signal(SIGINT,Printf); alarm(10); signal(SIGALRM,ALrm); for(;;) pause(); return 0; } 目的是测试在10...
#include
#include
#include
void Printf(int signo)
{
printf("received sigintn");
}
void ALrm(int signo)
{
printf("received Alrm");
}
int main()
{
signal(SIGINT,Printf);
alarm(10);
signal(SIGALRM,ALrm);
for(;;)
pause();
return 0;
}
目的是测试在10秒后,能表示闹钟到了,可是一般执行的话基本死机一样,必须要按ctrl+c才能显示^Creceived Alrmreceived sigint我觉得应该是sigint先执行的啊,怎么是alrm呢?
|
printf("received Alrm");
===>
printf("received Alrmn");
===>
printf("received Alrmn");
|
缓冲满,程序结束,还有显示flush,都会flush缓冲内容,细节可以上网搜搜。