Is it possible to ignore all signals?

后端 未结 3 991
無奈伤痛
無奈伤痛 2021-01-17 11:49

I have a server application which I want to protect from being stopped by any signal which I can ignore. Is there a way to ignore all possible signals at once, without setti

3条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-17 12:16

    Yes:

    #include 
    
    sigset_t mask;
    sigfillset(&mask);
    sigprocmask(SIG_SETMASK, &mask, NULL);
    

    This does not exactly ignore the signals, but blocks them; which in practice is the same effect.

    I guess there's no need to mention that SIGKILL and SIGSTOP cannot be blocked nor ignored in any way.

    For more detailed semantics, like mask inheritance rules and the like, check the man page

提交回复
热议问题