next up previous contents
Next: Editing Files Up: Process Management Previous: Running multiple processes

Sending Signals to Processes

Most processes do not like being sent signals. Their reaction to a signal is usually dying. Some processes however exit gracefully when sent a signal; others have a certain type of individual reaction to a signal, like re-reading their setup files.

We can send a signal to a process using the kill command. The kill command takes an optional signal type as a command line argument and a process ID, which can be found using the ps command. Carrying on from the previous example, lets kill vi:

$ps
  PID TTY STAT  TIME COMMAND
 1053 pp1 S N   0:00 bash
 1079 pp1 S N   0:03 emacs part3.tex&
 1209 pp1 T N   0:00 vi
 1211 pp1 R N   0:00 ps
$kill 1209
$ps
  PID TTY STAT  TIME COMMAND
 1053 pp1 S N   0:00 bash
 1079 pp1 S N   0:03 emacs part3.tex&
 1209 pp1 T N   0:00 vi
 1215 pp1 R N   0:00 ps
$

Our vi has not terminated itself. This is because we stopped it and although it has received our TERM signal, it cannot react to it. Let's start it running again:

$fg
vi
$ps
  PID TTY STAT  TIME COMMAND
 1053 pp1 S N   0:00 bash
 1079 pp1 S N   0:03 emacs part3.tex&
 1226 pp1 R N   0:00 ps
$

If we do not specify a signal to be sent, kill automatically sends the TERM signal, which tells programs to terminate themselves. If a program refuses to terminate itself, we can send it the KILL signal, which will externally abort the program. If we had sent our vi the KILL signal, it would have died immediately.

To find out the exact names of all signals we can type kill -l. We can find the signal we want and then send it to a process:

$kill -l 
 1) SIGHUP       2) SIGINT       3) SIGQUIT      4) SIGILL
 5) SIGTRAP      6) SIGIOT       7) SIGBUS       8) SIGFPE
 9) SIGKILL     10) SIGUSR1     11) SIGSEGV     12) SIGUSR2
13) SIGPIPE     14) SIGALRM     15) SIGTERM     17) SIGCHLD
18) SIGCONT     19) SIGSTOP     20) SIGTSTP     21) SIGTTIN
22) SIGTTOU     23) SIGURG      24) SIGXCPU     25) SIGXFSZ
26) SIGVTALRM   27) SIGPROF     28) SIGWINCH    29) SIGIO
30) SIGPWR
$ps
  PID TTY STAT  TIME COMMAND
 1053 pp1 S N   0:00 bash
 1079 pp1 S N   0:03 emacs part3.tex&
 1209 pp1 T N   0:00 vi
 1215 pp1 R N   0:00 ps
$kill -SIGKILL 1209
[2]+  Killed                 vi
$

We can specify the name or number of the signal we want to send on the command line.



Mark O. Stitson
Wed Sep 25 10:45:32 BST 1996