Of Zen and Computing

How to Kill a Mac OS X Application That Just Won’t Quit

Wednesday, August 20, 2008

Have you ever had a Mac OS X application freeze up on you, and simply refuse to quit? Well, if you ever do, there is a simple method of killing the application from the Terminal.

I have not had many applications hang on OS X, but every once-in-a-while it does happen. In fact, I got the idea for this article while writing another one about using Preview to import photos from the iPhone. Preview froze up on me, and I could not get it to quit. CMD-Q didn’t work, nor File → Quit, nor right-clicking on the dock icon and choosing “Quit” from the context menu. I solved the problem with a simple terminal command:

Screenshot of killing an applicaton from the Terminal

Start up Terminal

Terminal is located in the “Applications” folder. Open up a Finder window, click on “Applications” (on the left), then find and double-click on Terminal. If you have a version of OS X with Spotlight, the easiest way to do this is hit CMD-Space and search for “Terminal”.

Get the process ID of the hanging application

In order to kill a hanging process, you need its “pid” or process id. I entered ps -A | grep Preview in order to do this. ps -A yields all processing running on the system, from all users. I piped the output of this command to grep Preview, which searches the output of ps -A for occurrences of the string “Preview”.

This doesn’t all need to make sense for you right away. The most important thing you should take away from that previous paragraph is that I entered ps -A | grep Preview into a command prompt in order to get the process id of the hanging application.

Replace “Preview” with the name of the application that is not responding. Use the exact case in which the application’s name appears — grep Preview is not the same as grep preview. If you are not sure, try using only part of the application’s name such as ps -A | grep review.

The line of output that appears directly below ps -A | grep Preview is the output of that command — the 5 digit number (30995 in this case) all the way to the left is the process ID.

Shut the application

Now that you have the process ID, you must tell the system to shut down that process. I used the command “kill -9 30995″ to do this. In short, that command means “shut down process 30995 right now, no questions asked”.

Once I issued this command, the system shut down Preview. To double-check, I ran ps -A | grep Preview again, and as you can see that the only output was the grep Preview command itself. Success.

File under: Tips & Tricks

Digg icon StumbleUpon icon del.icio.us icon Facebook icon

Other articles related to this page

© 2006-2008 OfZenAndComputing.com
E-mail Disclaimer | Terms of Service & Disclaimer | Sitemap

Subscription Options
Search Our Archive of How-To Articles and Blog Posts