The name "kill" is a misnomer; it
sounds as if the command is inherently destructive, but
kill simply sends signals to programs. Only a
few signals will actually kill the process by default. Most signals
can be caught by the process, which may choose to either perform a
specific action or ignore the signal. When a process is in a zombie
or uninterruptible sleep( )state, it might ignore
any signals.
The following example will help dispel any fear of using this
command. Most people who are familiar with the command line know that
pressing Ctrl-C will usually terminate a process running in a
console. For example, it is common to execute:
panic% tail -f /home/httpd/httpd_perl/logs/error_log
to monitor the Apache server's
error_log file. The only way to stop
tail is by pressing Ctrl-C in the console in
which the process is running. The same result can be achieved by
sending the INT (interrupt) signal to this process. For example:
panic% kill -INT 17084
When this command is run, the tail process is
aborted, assuming that the process identifier (PID) of the
tail process is 17084.
panic% ps auxc | grep tail
On a System V Unix flavor such as Solaris, the following command may
be used instead:
panic% ps -eaf | grep tail
In the first part of the command, ps prints
information about all the current processes. This is then piped to a
grep command that prints lines containing the
text "tail". Assuming only one such
tail process is running, we get the following
output:
root 17084 0.1 0.1 1112 408 pts/8 S 17:28 0:00 tail
The first column shows the username of the account running the
process, the second column shows the PID, and the last column shows
the name of the command. The other columns vary between operating
systems.
Processes are free to ignore almost all signals they receive, and
there are cases when they will. Let's run the
less command on the same
error_log file:
panic% less /home/httpd/httpd_perl/logs/error_log
Neither pressing Ctrl-C nor sending the INT signal will kill the
process, because the implementers of this utility chose to ignore
that signal. The way to kill the process is to type
q.
Sometimes numerical signal values are used instead of their symbolic
names. For example, 2 is normally the numeric equivalent of the
symbolic name INT. Hence, these two commands are equivalent on Linux:
panic% kill -2 17084
panic% kill -INT 17084
On Solaris, the -s option is used when working
with symbolic signal names:
panic% kill -s INT 17084
To find the numerical equivalents, either refer to the
signal(7) manpage, or ask Perl to help you:
panic% perl -MConfig -e 'printf "%6s %2d\n", $_, $sig++ \
for split / /, $Config{sig_name}'
If you want to send a signal to all processes with the same name, you
can use pkill on Solaris or
killall on Linux.