当前位置:  技术问答>linux和unix

怎么会这样呢?想了半天不懂啊

    来源: 互联网  发布时间:2016-11-20

    本文导语:  #include #include #include void sigusr1handler(int signo) { printf("catch SIGUSR1n"); sleep(5); printf("back to mainn"); } int main() { struct sigaction act; act.sa_handler=sigusr1handler; act.sa_flags =SA_NODEFER; act.sa_sigaction=NULL; sigemptyset(&act.sa_mask); if(sigaction(SIGUSR1...


#include
#include
#include


void sigusr1handler(int signo)
{
printf("catch SIGUSR1n");
sleep(5);
printf("back to mainn");
}

int main()
{
struct sigaction act;
act.sa_handler=sigusr1handler;
act.sa_flags =SA_NODEFER;
act.sa_sigaction=NULL;
sigemptyset(&act.sa_mask);
if(sigaction(SIGUSR1,&act,NULL)==-1){
  perror("fail to set handler for SIGCHILD");
  exit(1);
  }
printf("process beginn");
sleep(20);
printf("donen");
return 0;
}

这个小程序,在程序休眠期间,向进程发送USR1信号,本来应该出现catch SIGUSR1的,然后休眠5秒的,可实际上却出现的是用户定义信号 1,然后程序就结素了。感觉usr1信号完全没有被捕获,怎么回事??


|

act.sa_handler=sigusr1handler;
act.sa_flags =SA_NODEFER;
//act.sa_sigaction=NULL;

If you have a question, please ask the "man" for help.
哈哈,man sigaction里面说的很详细,sa_handler和sa_sigaction在某些平台上,不能够同时设置。
 struct sigaction {
     void     (*sa_handler)(int);
     void     (*sa_sigaction)(int, siginfo_t *, void *);
     sigset_t   sa_mask;
     int        sa_flags;
     void     (*sa_restorer)(void);
 };

“On some architectures a union is involved: do not assign to both sa_handler and sa_sigaction.”

    
 
 
 
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。














站内导航:


特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

©2012-2021,,E-mail:www_#163.com(请将#改为@)

浙ICP备11055608号-3