These classnotes are depreciated. As of 2005, I no longer teach the classes. Notes will remain online for legacy purposes

UNIX01/The Kill Command

Classnotes | UNIX01 | RecentChanges | Preferences

Killing A Process

Sometimes it is necessary to kill a process. The process could not be responding to normal imput, it could be a run-away process (consuming system resources and constantly growing), or it could simply be a zombie. The command to kill a process is.... surprise, surprise.... kill!

Kill has the following usage:

 kill [OPTION(s)] PID1 [PID2 ...]

Kill is actually more general than just for "killing" processes. In truth, it is just a mechanism for sending signals to a running process. Many of these signals do result in terminating the process, but not all.

Even though kill does have many other options, by far the most common usage is as follows:

 kill -SIGNAL PID1 [PID2 ...]

where "SIGNAL" is either the alpha-numeric or numerical specification of a signal. To list the possible signals that kill can submit, run kill with the "-l" option:

  sam@rygel:~$ kill -l
  1) SIGHUP       2) SIGINT       3) SIGQUIT      4) SIGILL
  5) SIGTRAP      6) SIGABRT      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      31) SIGSYS      32) SIGRTMIN    33) SIGRTMIN+1
 34) SIGRTMIN+2  35) SIGRTMIN+3  36) SIGRTMIN+4  37) SIGRTMIN+5
 38) SIGRTMIN+6  39) SIGRTMIN+7  40) SIGRTMIN+8  41) SIGRTMIN+9
 42) SIGRTMIN+10 43) SIGRTMIN+11 44) SIGRTMIN+12 45) SIGRTMIN+13
 46) SIGRTMIN+14 47) SIGRTMIN+15 48) SIGRTMAX-15 49) SIGRTMAX-14
 50) SIGRTMAX-13 51) SIGRTMAX-12 52) SIGRTMAX-11 53) SIGRTMAX-10
 54) SIGRTMAX-9  55) SIGRTMAX-8  56) SIGRTMAX-7  57) SIGRTMAX-6
 58) SIGRTMAX-5  59) SIGRTMAX-4  60) SIGRTMAX-3  61) SIGRTMAX-2
 62) SIGRTMAX-1  63) SIGRTMAX

A signal can be sent as either the symbolic name or the signal number. For example, a SIGKILL can be sent as either:

 kill -SIGKILL 483
or
 kill -9 483

The most commonly used signals are as follows:

SIGHUP - 1
This is the "hang-up" signal. The signal has numerous interpretations by various programs, but most commonly it causes the program to reload its configuration file(s) and/or re-open it's interfaces (files/pipes/etc). It should not terminate the process.
SIGTERM - 15
This is the polite termination signal. This signal tells the program to stop what it's doing and exit cleanly- saving its work and politely asking any controlling process (or user) if it was alright to quit. Basically, the process is told to quit, but not required to obey that request. Because it is polite, it is probably not something that will work on run-away or zombied processes.
SIGKILL - 9
Often called "kill nasty", this is the way to forceably terminate a process. When a process is killed thusly, it has no time to shutdown nicely, it is just terminated flat out. This should be considered a "last resort" to end a process. If you stay with UNIX long enough, you will encounter many kill -9 jokes.
[Comic about "kill nasty"] from [Streuna Inertia].

killall

What if you want to kill all processes of a certain name without having to look up each process's PID, the command to use is killall. The usage is very similar to normal kill:
 killall -SIGNAL PROCESS_NAME ...

For example, if I wanted to send a SIGKILL (kill nasty) to all Netscape processes (Netscape used to be notorious for having run-away and zombie processes), my command would be

 killall -SIGKILL netscape

One of my "claims-to-fame" was that I used to draw a comic strip called "Strenua Inertia" (which loosely meant "working hard at nothing"). I once drew a Halloween strip referencing what we've been talking about today. That strip was Slashdotted (which nearly brought my server to its knees). You can see the strip [here].

PROJECT : Kill Stuff

Spawn several processes and practice killing them in a variety of ways:

  1. Spawn Mozilla. Pretend that it has run-away and must be killed. Locate it's PID and kill it "nasty".
  2. Spawn several XTerms. From some other terminal (such as KDE's Konsole) kill all of them. Use the "terminate" or "polite" signal.
  3. You have just reconfigured the SSH server daemon (sshd). Send it a "hang-up" signal to tell it to reload it's configuration files.


Classnotes | UNIX01 | RecentChanges | Preferences
This page is read-only | View other revisions
Last edited August 8, 2003 11:09 pm (diff)
Search:
(C) Copyright 2003 Samuel Hart
Creative Commons License
This work is licensed under a Creative Commons License.