ptg10805159
314 Signals Chapter 10
Linux 3.2.0 each support 31 different signals, whereas Solaris 10 supports 40 different
signals. FreeBSD, Linux, and Solaris, however,support additional application-defined
signals introduced to support real-time applications. Although the POSIX real-time
extensions aren’t covered in this book (refer to Gallmeister[ 1995 ]for moreinformation),
as of SUSv4 the real-time signal interfaces have moved to the base specification.
Signal names areall defined by positive integer constants (the signal number) in the
header<signal.h>.
Implementations actually define the individual signals in a different header file, but this
header file is included by<signal.h>.It is considered bad form for the kernel to include
header files meant for user-level applications, so if the applications and the kernel both need
the same definitions, the information is placed in a kernel header file that is then included by
the user-level header file. Thus both FreeBSD 8.0 and Mac OS X 10.6.8 define the signals in
<sys/signal.h>.Linux 3.2.0 defines the signals in<bits/signum.h>,and Solaris 10
defines them in<sys/iso/signal_iso.h>.
No signal has a signal number of 0.We’ll see in Section 10.9 that thekillfunction uses
the signal number of 0 for a special case. POSIX.1 calls this value thenull signal.
Numerous conditions can generate a signal:
•The terminal-generated signals occur when users press certain terminal keys.
Pressing the DELETE key on the terminal (or Control-C on many systems)
normally causes the interrupt signal (SIGINT) to be generated. This is how to
stop a runaway program. (We’ll see in Chapter 18 how this signal can be
mapped to any character on the terminal.)
•Hardwareexceptions generate signals: divide by 0, invalid memory reference,
and the like. These conditions areusually detected by the hardware, and the
kernel is notified. The kernel then generates the appropriate signal for the
process that was running at the time the condition occurred. For example,
SIGSEGVis generated for a process that executes an invalid memory reference.
•Thekill( 2 )function allows a process to send any signal to another process or
process group. Naturally,thereare limitations: we have to be the owner of the
process that we’resending the signal to, or we have to be the superuser.
•Thekill( 1 ) command allows us to send signals to other processes. This
program is just an interface to thekillfunction. This command is often used
to terminate a runaway background process.
•Softwareconditions can generate signals when a process should be notified of
various events. These aren’t hardware-generated conditions (as is the divide-
by-0 condition), but softwareconditions. Examples are SIGURG(generated
when out-of-band data arrives over a network connection),SIGPIPE(generated
when a process writes to a pipe that has no reader), andSIGALRM(generated
when an alarm clock set by the process expires).
Signals areclassic examples of asynchronous events. They occur at what appear to
be random times to the process. The process can’t simply test a variable (such as
errno) to see whether a signal has occurred; instead, the process has to tell the kernel
‘‘if and when this signal occurs, do the following.’’