Hunt And Kill A Process

Hunt And Kill A Process

Have you ever run an application for a while and then it just freezes?  So then you try to end the process. You try to do a Command-Q; it doesn’t work. Then you try clicking on the application-name on the menu bar to do a  “Quit <application name>”; it doesn’t work. Last you try doing a control-click or right-click on the application’s icon in the dock and then clicking on Quit only to find this
doesn’t work either. At this point you know you have a hung process — an application just sitting
there in limbo not responding to any of your prompts.

What Do You Do?
Because the Mac OS X is based upon Unix you’ll have to revert to
a Terminal (unix) command. If you haven’t used Terminal before, it is basically a command you type and execute inside of a window. Similar to windows, it’s like opening up a DOS command prompt and entering a command and hitting the Enter key.  You can find Terminal by doing a Spotlight  – type in terminal – then click on Terminal. A Terminal window should appear. Terminal can also be found by clicking on Finder – Applications – Utilities – Terminal.

Steps To Hunt And Kill
Here are the steps to hunt and kill a hung process. Let’s say the application hung is Firefox.
1) At the Terminal window prompt, type in ps -A | grep -i  firefox
2) When the system comes back it will give you a results list similar to this:

248 ??       242:55.51 /Applications/Firefox.app/Contents/MacOS/firefox-bin -psn_0_2486879
5535 ttys000    0:00.00 grep -i firefox

The results list format is:  process id number, controlling terminal,  application name. The important thing to note is the process id number.  You will need this for the kill command that will be issued next.
In this case the process id number is 248 for firefox.
3) Next, at the Terminal prompt issue the command kill -9  248
4) The Terminal command prompt will return; it will look like nothing happened.
5) But now issue the ps command again:  ps -A | grep -i  firefox
6) And the results list that is returned should be void of the 248 process, firefox in this case.
7)  Process id 248 has been removed. You’re done!

A Word About The PS Command
You don’t have to fully understand all the details of the ps (process state) command, but  basically
the ps -A tells the system to list all the active processes that are running at the moment.
If you issued this command by itself, it will give you a fairly long results list depending upon
what’s running on your system at the moment. The pipe symbol (|) is used as a separator to
add in the grep command. grep is a find command. So if I type in grep firefox it will look for
the occurrence of “firefox” in lowercase letters. If I add in the -i option to the command,
grep -i firefox, this tells the system to ignore the case. As you may know, in Unix firefox
and Firefox are not the same; upper and lower case letters are two different things.  The kill -9 248
command tells the system to stop the process id 248 no matter what. It won’t give you any warnings;
it will just stop it.

Kill With Care
One last note, use this hunt and kill process as a last resort. If you have no other way to exit
out of the application, by all means use it. However, any data files that are opened while the application
is “hung” may be lost or corrupted after the process is killed. So always try to exit normally first.

place related posts links here. <-->
If you enjoyed this article, you may also like:
  • No Related Post

One Response to “Hunt And Kill A Process”

  1. good share, great article, very usefull for us…thanks!

Leave a Reply


Google Analytics <--> Aweber Analytics <-->