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 setting them one by one?
Yes:
#include <signal.h>
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With