Skip to content
Advertisement

Interruption of signal handler with other signal?

Can a signal handler be interrupted by another signal (except of SIGKILL, SIGSTOP)?

Therefore, do I need to check for EINTR in my signal handler when calling interruptable syscalls?

(Linux and other Unixes)

Advertisement

Answer

Yes, the execution of a signal handler may itself be interrupted by the delivery of another signal.

There are a few nuances, however.

By default, user-defined signal handlers temporarily block the very signal which invoked them. This is the default behavior of sigaction unless the SA_NODEFER flag is set. (This is also the behavior of the older, discouraged signal function, at least on most implementations.)

Additionally, sigaction can explicitly block signals during the handler’s execution by setting the sa_mask member of the const struct sigaction. Most code you see will explicitly empty this member during struct initialization, though it is often more robust to sigfillset this member and not worry about interruptions.

So, again, yes. Handle EINTR, errno, &c. as appropriate, or, better yet, design the handler to do no more than set a sig_atomic_t flag and avoid many worries.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement