Advanced Programming in the UNIX® Environment

(lily) #1
ptg10805159

336 Signals Chapter 10


What happens if a blocked signal is generated morethan once beforethe process
unblocks the signal? POSIX.1 allows the system to deliver the signal either once or
morethan once. If the system delivers the signal morethan once, we say that the
signals arequeued. Most UNIX systems, however,donotqueue signals unless they
support the real-time extensions to POSIX.1. Instead, the UNIX kernel simply delivers
the signal once.

With SUSv4, the real-time signal functionality moved from the real-time extensions to the base
specification. As time goes on, moresystems will support queueing signals even if they don’t
support the real-time extensions.We discuss queueing signals further in Section 10.20.
The manual pages for SVR2 claimed that theSIGCLDsignal was queued while the process was
executing itsSIGCLDsignal handler.Although this might have been true on a conceptual
level, the actual implementation was different. Instead, the signal was regenerated by the
kernel as we described in Section 10.7. In SVR3, the manual was changed to indicate that the
SIGCLDsignal was ignored while the process was executing its signal handler forSIGCLD.
The SVR4 manual removed any mention of what happens toSIGCLDsignals that are
generated while a process is executing itsSIGCLDsignal handler.
The SVR4sigaction( 2 )manual page in AT&T [1990e] claims that theSA_SIGINFOflag
(Figure10.16) causes signals to be reliably queued. This is wrong. Apparently,this feature
was partially implemented within the kernel, but it is not enabled in SVR4. Curiously,the
SVID didn’t make the same claims of reliable queuing.

What happens if morethan one signal is ready to be delivered to a process?
POSIX.1 does not specify the order in which the signals aredelivered to the process.
The Rationale for POSIX.1 does suggest, however,that signals related to the current
state of the process be delivered beforeother signals. (SIGSEGVis one such signal.)
Each process has asignal maskthat defines the set of signals currently blocked from
delivery to that process. Wecan think of this mask as having one bit for each possible
signal. If the bit is on for a given signal, that signal is currently blocked.Aprocess can
examine and change its current signal mask by callingsigprocmask,which we
describe in Section 10.12.
Since it is possible for the number of signals to exceed the number of bits in an
integer,POSIX.1 defines a data type, calledsigset_t,that holds asignal set.The
signal mask, for example, is stored in one of these signal sets. We describe five
functions that operate on signal sets in Section 10.11.

10.9 killandraise Functions


Thekillfunction sends a signal to a process or a group of processes. Theraise
function allows a process to send a signal to itself.

Theraisefunction was originally defined by ISO C. POSIX.1 includes it to align itself with
the ISO C standard, but POSIX.1 extends the specification ofraiseto deal with threads (we
discuss how threads interact with signals in Section 12.8). Since ISO C does not deal with
multiple processes, it could not define a function, such askill,that requires a process ID
argument.
Free download pdf