ptg10805159
Section 10.8 Reliable-Signal Terminology and Semantics 335
The problem with this program is that the call tosignalat the beginning of the
signal handler invokes item 2 from the preceding discussion—the kernel checks
whether a child needs to bewaited for (which is the case, since we’reprocessing a
SIGCLDsignal), so it generates another call to the signal handler.The signal handler
callssignal,and the whole process starts over again.
To fixthis program, we have to move the call tosignalafter the call towait.By
doing this, we callsignalafter fetching the child’s termination status; the signal is
generated again by the kernel only if some other child has since terminated.
POSIX.1 states that when we establish a signal handler forSIGCHLDand thereexists a
terminated child we have not yetwaited for, it is unspecified whether the signal is generated.
This allows the behavior described previously.But since POSIX.1 does not reset a signal’s
disposition to its default when the signal occurs (assuming that we’reusing the POSIX.1
sigactionfunction to set its disposition), there is noneed for us to ever establish a signal
handler forSIGCHLDwithin that handler.
Be cognizant of theSIGCHLDsemantics for your implementation. Be especially
aware of some systems that#define SIGCHLDto beSIGCLD, or vice versa. Changing
the name may allow you to compile a program that was written for another system, but
if that program depends on the other semantics, it may not work.
Of the four platforms described in this text, only Linux 3.2.0 and Solaris 10 defineSIGCLD.On
these platforms,SIGCLDis equivalent toSIGCHLD.
10.8 Reliable-Signal Terminology and Semantics
We need to define some of the terms used throughout our discussion of signals. First, a
signal isgeneratedfor a process (or sent to a process) when the event that causes the
signal occurs. The event could be a hardwareexception (e.g., divide by 0), a software
condition (e.g., analarmtimer expiring), a terminal-generated signal, or a call to the
killfunction. When the signal is generated, the kernel usually sets a flag of some
form in the process table.
We say that a signal isdeliveredto a process when the action for a signal is taken.
During the time between the generation of a signal and its delivery,the signal is said to
bepending.
Aprocess has the option ofblockingthe delivery of a signal. If a signal that is
blocked is generated for a process, and if the action for that signal is either the default
action or to catch the signal, then the signal remains pending for the process until the
process either (a) unblocks the signal or (b) changes the action to ignorethe signal. The
system determines what to do with a blocked signal when the signal is delivered, not
when it’s generated. This allows the process to change the action for the signal before
it’s delivered. Thesigpendingfunction (Section 10.13) can be called by a process to
determine which signals areblocked and pending.