Signals

Signals are a simple Unix mechanism for controlling processes. A signal is a 5-bit message to a process that requires immediate attention. Each signal has a default action associated with it; for some signals, you can change this default action. Signals are generated by exceptions, which include:

  • Attempts to use illegal instructions

  • Certain kinds of mathematical operations

  • Window resize events

  • Predefined alarms, including expiration of a timer

  • The user pressing an interrupt key on a terminal

  • Another program using the kill( ) or killpg( ) system calls

  • A program running in the background attempting to read from or write to its controlling terminal

  • A child process calling exit or terminating abnormally

The system default may be to ignore the signal, to terminate the process receiving the signal (and, optionally, generate a core file), or to suspend the process until it receives a continuation signal. Some signals can be caught—that is, a program can specify a particular function that should be run when the signal is received. As originally designed, Unix supports exactly 31 signals. Some vendors, such as Sun, have extended this set to include more signals. The signals and types are usually listed in the files /usr/include/signal.h and /usr/include/sys/signal.h. Table B-6 contains a summary of the 31 standard signals.

Table B-6. Unix signals

Signal name

Number[a]

Key[b]

Meaning

SIGHUP

1

Hangup (sent to a process when a modem or network connection is lost)

SIGINT

2

Interrupt ...

Get Practical UNIX and Internet Security, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.