The use of pause()
in the signal handler does not permit the signal to be delivered another time. Before the signal handler was entered, the signal was either masked or reset to its default action (most implementations do the former).
Another problem is that a signal from kill()
may be coalesced with another instance of the same signal number. This happens if the receiving process does not get to run soon enough: if a new signal comes in when another is already pending for the same signal number, the new signal may be discarded. You can avoid this by using different signal numbers for each sender or by using sigqueue()
and a handler installed with sigaction()
with SA_SIGINFO
set in sa_flags
. Neither of these scale indefinitely.
It is wise to avoid use of the obsolete functions pause()
and signal()
. It is better to use sigsuspend()
and sigaction()
instead.
You can temporarily block signals using sigprocmask()
or pthread_sigmask()
. This will let you avoid race conditions such as signals coming in before the handler is installed.
The sigwait()
function lets you handle signals in the main flow of the program.
Per convention, a normal termination is done with SIGTERM
, not SIGQUIT
. Note that the default action of SIGQUIT
includes a core dump or similar.