How to kill a Unix process
From http://www.ncl.ac.uk/iss/unix/unixhelp/kill.html and http://www.decf.berkeley.edu/help/unix/kill.html
If you are logged in to a Unix system and your session "hangs" or "freezes" (i.e. nothing happens for a long time and it does not respond to Ctrl/Q Ctrl/C or Ctrl/D), you can attempt to unfreeze it yourself by "killing" the process which has stopped your session.You can also use Ctrl/Z to get out of a process in UNIX.
Or you could just type ps -u
Login to the system where your session is frozen
Type the command:
w usid
where usid is your own username. This will produce a line of output for each login something like this:
9:53am up 82 day(s), 15:58, 132 users, load average: 6.50, 6.25, 5.70
User tty login@ idle JCPU PCPU what
nabc pts/160 9:12am -csh
nabc pts/166 9:53am w nabcNote the contents of the tty column for the frozen login -- in this example attached to pts/160.
Type the command
ps -t tty
where tty is the tty designation noted above. For example
ps -t pts/160
The output will be something like
PID TTY TIME CMD
20865 pts/160 0:00 elm
18986 pts/160 0:00 cshNote (under PID) which of your processes issued the command which is now "hung".
Type the command
kill -KILL xxxxx
where xxxxx is the process number (PID) of the frozen process. For example
kill -KILL 20865
A little explanation on that -9 thing and kill.
The `kill' command
Sometimes a process will ignore both of these keystroke-generated
signals. This will happen when a process has been `backgrounded'
or `submitted', in which case you can use the `kill' command to
abort it. It may also happen when your terminal is frozen in an
unresponsive state, in which case it may be necessary to kill
your login process (i.e. log you out) just to return your termi-
nal to a sensible state.
The `kill' command has the general form "kill -N PID", where you
replace `PID' with a process identification number and replace
`N' with a `signal' number. Usually, `N' will be `1' and the
PID, if you do not already know it, can be learned through the
`ps' command as described below. This command causes the speci-
fied signal to be sent to the specified process.
Signal numbers
Signal number `1', a `hangup' signal, is recommended because it
should kill the process and, if it is an editor, save the buffer.
Signal number `9', a `kill' signal, is the surest way to kill a
process and is recommended only as a last resort since it will
not save editor buffers.
You may wish to note that the interrupt and quit (keystroke) sig-
nals mentioned above can be sent to a process by replacing `N'
with `2' and `3', respectively. There are 15 different signals
that can be sent to a process via `kill'. Each of them conveys
slightly different information but generally causes death, whence
the name of the command.
Comments