Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to ignore all signals?

Tags:

c

unix

signals

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?

like image 471
Joó Ádám Avatar asked Apr 06 '12 17:04

Joó Ádám


1 Answers

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

like image 192
C2H5OH Avatar answered Sep 22 '22 11:09

C2H5OH