You do 2 things here:
Filling a sigset_t . Sigset_t is just a set of values for signals and is used in various system calls. You can:
- Create an empty sigset_t (sigemptyset () file
- Add signal to set (sigaddset ())
- Delete signal on set (sigdelset ())
- etc...
Setting the signal mask for the signal handler. You do this by manipulating the sigset_t sa_mask struct sigaction when you set up a signal handler with a call to sigaction ().
The signal mask of the signal handler means that during the execution of the signal handler, the signals that are in the mask will be blocked, that is, these signals will not be processed until they are blocked. When the signal handler is finished, the signals in will be unlocked. A signal that is blocked is not “lost”, it will be processed when this particular signal is unblocked again.
sigaddset(&act.sa_mask, SIGINT); means that the SIGINT signal cannot appear when the code for the SIGALRM handler is executed.
On the other hand, if you comment out sigaddset(&act.sa_mask, SIGINT); , you will only have an empty list of signals created using sigemptyset(&act.sa_mask); . Thus, any signals that occur during the operation of the SIGALRM handler can supplant this handler and execute a signal handler for this other signal.
For SIGINT, you usually don’t notice any difference with manual testing - it is unlikely that you will hit CTRL-C exactly when your SIGALRM handler is running, and your SIGALRM handler is probably fast enough for you to not notice, SIGINT was a little delayed.
source share