kill

On occasion, programs misbehave and you'll need to put them back in line. The program for this kind of administration is called kill(1), and it can be used for manipulating processes in several ways. The most obvious use of kill is to kill off a process. You'll need to do this if a program has run away and is using up lots of system resources, or if you're just sick of it running.

In order to kill off a process, you'll need to know its PID or its name. To get the PID, use the ps command as was dicsussed in the last section. For example, to kill off process 4747, you'd issue the following:

   $ kill 4747

Note that you'll have to be the owner of the process in order to kill it. This is a security feature. If you were allowed to kill off processes started by other users, it would be possible to do all sorts of malicious things. Of course, root can kill off any process on the system.

There's another variety of the kill command called killall(1). This program does exactly what it says: it kills all the running processes that have a certain name. If you wanted to kill off all the running vim processes, you could type the following command:

   $ killall vim

Any and all vim processes you have running will die off. Doing this as root would kill off all the vim processes running for all users. This brings up an interesting way to kick everyone (including yourself) off the system:

   # killall bash

Sometimes a regular kill doesn't get the job done. Certain processes will not die with a kill. You'll need to use a more potent form. If that pesky PID 4747 wasn't responding to your kill request, you could do the following:

   $ kill -9 4747

That will almost certainly cause process 4747 to die. You can do the same thing with killall. What this is doing is sending a different signal to the process. A regular kill sends a SIGTERM (terminate) signal to the process. kill -9 sends a SIGKILL (kill) signal to the process. There's a whole list of signals at your disposal. You can get a listing of signals by typing the following:

   $ 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

The number must be used for kill, while the name minus the leading “SIG” can be used with killall. Here's another example:

   $ killall -KILL vim

A final use of kill is to restart a process. Sending a SIGHUP will cause most processes to re-read their configuration files. This is especially helpful for telling system processes to re-read their config files after editing.