UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 38.7 Why ps Prints Some Commands in Parentheses Chapter 38
Starting, Stopping, and Killing Processes
Next: 38.9 Killing Foreground Jobs
 

38.8 What Are Signals?

Signals are a simple, but important means of interprocess communication. Interprocess communication sounds fancy, but it's really a simple concept: it's the means by which one program sends a message to another program. It's common to think of signals as special messages sent by the UNIX kernel (1.14) but, in fact, any program can signal any other program.

What kinds of messages can you send with a signal? Relatively few, in reality. Signals aren't "arbitrary" messages, like letters; they are a small group of pre-defined messages, each with its own special meaning. System V UNIX supports 16 signals, each of which is assigned a number; BSD-derived UNIX implementations and SVR4 have 32 signals. Table 38.2 lists some of the more commonly used signals. It also lists keyboard characters that send common signals on BSD systems (these can be changed; see article 5.9).

Table 38.2: Common Signals
Signal NameNumberMeaning and Typical Use
HUP1Hangup - stop running. Sent when you log out or disconnect a modem.
INT2Interrupt - stop running. Sent when you type CTRL-c.
QUIT3Quit - stop running (anddump core (52.9)).Sent when you type CTRL-\.
KILL9Kill - stop unconditionally and immediately; a good "emergency kill."
SEGV11Segmentation violation - you have tried to access illegal memory.
TERM15Terminate - terminate gracefully, if possible.
STOP17Stop unconditionally and immediately; continue with CONT.
TSTP18Stop - stop executing, ready to continue (in either background or foreground). Sent when you type CTRL-z. stty (5.9) calls this susp.
CONT19Continue - continue executing after STOP or TSTP.
CHLD20Child - a child process's status has changed.
USR130User-defined signal.

While this list isn't definitive, it shows you the types of things signals can do. Many signals, like SIGSEGV, are warning or error messages. You've probably seen the frustrating "segmentation violation" message. That message came when the kernel detected something wrong and sent your program a SIGSEGV signal; in response, your program quit. Others signals, like SIGTSTP, are generated in response to special characters on the keyboard. And a lot of signals just say, "Your time is up, goodbye!"

When a process receives a signal, it can take a number of actions; for example:

You've probably read that the command kill -9 is guaranteed to kill a process. Why? Two special signals in Table 38.2 can't be caught or ignored: the KILL and STOP signals.

The kill (38.10) command doesn't kill - it really does nothing more than send signals. As you now know, signals often bring death and destruction - but there's no necessary reason for them to do so.

- ML


Previous: 38.7 Why ps Prints Some Commands in Parentheses UNIX Power ToolsNext: 38.9 Killing Foreground Jobs
38.7 Why ps Prints Some Commands in Parentheses Book Index38.9 Killing Foreground Jobs

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System