Masking signals

While a process is running, what if it wants to block (or mask) certain signals? This is indeed possible via the API interface; in fact, the second member of the sigaction(2) structure is the signal mask, the mask of signals to block from delivery to the process while the signal handler function is running. A mask typically implies a bitwise-or of signals:

...
/* Additional set of signals to be blocked. */
__sigset_t sa_mask;
...

Do notice the previous comment; it implies some signal is already being blocked. Yes, indeed; let's say a process traps a signal n via the sigaction system call. At some later point that signal n is delivered to it; while our process handles the signal—that is, runs the code of its signal handler—that signal n is blocked from delivery to the process. For how long is it blocked? Until we return from the signal handler. In other words, the OS auto-blocks the signal currently being handled. This usually is precisely what we want, and it works to our advantage.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset