Killing your processes
Sometimes, you will need to kill off one of your processes. You may have
started a process you didn't really want, or you may have a process that was
disconnected. Your terminal might have frozen, or you may have simply left
yourself logged in. Under normal circumstances, you do not need to get
anyone to kill your jobs for you. This document explains how to do it
yourself.
-
Find the process id (PID) of the process you want to kill. The command
ps -fu [your username]
will give it to you. The second column of the output, the PID, has the
number you are looking for. If you are logged in more than once, make sure
you check the column with the "pts", which gives the terminal you are logged
on to. Check which one has the process performing the
ps.
This is the one you are on. It is easy to shoot yourself in the
foot by killing the process that you are working from, so be careful.
-
Once you know the PID, use the
kill(1)
command to get rid of it. The basic syntax is
% kill PID
There are different kinds of kill signals, which differ in how easily a
process can resist being killed, and in what they allow the process to do
before being killed. These options can be described by a name or by a
number. For full descriptions, use
% man -s 5 signal
There are two options which you may find useful. If you have to kill an emacs
session, or something else that you want to save information before it dies
completely (or if you want to give the program a chance to die gracefully),
kill -HUP
PID
(or
kill -1
PID)
may be useful. This sends a hang-up signal, which
gives the program time to do any cleanup that it is willing to do before
dying. This gives you a much better chance of recovering your file from
a text editor, for instance.
One other useful version of this command is
kill -9
PID
(or
kill -KILL
PID).
This is for those
processes that will not die with just plain
kill.
There are a few
circumstances under which even this will not work. These are explained in
the NOTES section of this document. In these cases you must either talk to
a staff member or ignore it, depending on the circumstances.
-
Check to see if the process is dead by typing
ps -fu [your username]
again. If it is not, try
kill -9
PID
if you have not already.
If it still does not die, see the notes below.
Notes:
Reasons a process won't die:
-
When you do the final
ps -fu [your username]
you get
% [your username] PID 1862412 0:02
or
% [your username] PID 1862412 0:02
instead of
% [your username] PID 1864212 80 10:11:27 pts/45 0:93 -tcsh
These processes are waiting for something, and are usually unkillable. Kill
all associated processes, and they should go away eventually (it may not be
until the machine reboots next). See the
ps (1)
man page for more information.
-
The process shows up when you do a
w
or
who,
but not when you do a
ps.
The process is not actually there--it is an accounting error. It will not
go away until someone uses that terminal, or the machine reboots. There
isn't anything that can be done.
For more information, look at the manual pages on
ps (1)
and
kill (1).
Copyright (c) HMC Computer Science Department.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.1
or any later version published by the Free Software Foundation;
with the no Invariant Sections, with no
Front-Cover Texts, and with no Back-Cover Texts.
A copy of the license is included in the section entitled ``GNU Free Documentation License.''
|