Signals: Fundamental Concepts 419
The sigaction() system call provides more control and flexibility than signal()
when setting the disposition of a signal. First, we can specify a set of additional sig-
nals to be blocked when a handler is invoked. In addition, various flags can be used
to control the actions that occur when a signal handler is invoked. For example,
there are flags that select the older unreliable signal semantics (not blocking the
signal causing invocation of a handler, and having the disposition of the signal
reset to its default before the handler is called).
Using pause(), a process can suspend execution until a signal arrives.
Further information
[Bovet & Cesati, 2005] and [Maxwell, 1999] provide background on the imple-
mentation of signals in Linux. [Goodheart & Cox, 1994] details the implementa-
tion of signals on System V Release 4. The GNU C library manual (available
online at http://www.gnu.org/) contains an extensive description of signals.
20.16 Exercises
20-1. As noted in Section 20.3, sigaction() is more portable than signal() for establishing a
signal handler. Replace the use of signal() by sigaction() in the program in Listing 20-7
(sig_receiver.c).
20-2. Write a program that shows that when the disposition of a pending signal is
changed to be SIG_IGN, the program never sees (catches) the signal.
20-3. Write programs that verify the effect of the SA_RESETHAND and SA_NODEFER flags when
establishing a signal handler with sigaction().
20-4. Implement siginterrupt() using sigaction().