Posts Tagged ‘tutorial’

Killing Finder or Dock (or any other mac OS X application)

Wednesday, March 11th, 2009

When an application in OS X is stalling on you and you have given up on regaining control of it, the best thing to do is kill it before it takes down your whole machine. Usually you would right click on the application icon in the Dock and choose the menu item “Quit” or “Force Quit” if available and that should do the trick.

Dock Menu When Right Clicking Application

Dock Menu When Right Clicking Application

Or you could click on the top left corner “apple” icon which will bring up a menu where you will see something called “Force Quit”. Choosing that option will open a small window with a list of the running applications which you can forcibly kill.

Force Quit Applications

Force Quit Applications

Sometimes though a key component of OS X fails on you which you don’t have an option to force quit like the above mentioned methods. I came to such a situation when the Dock froze on me the other day. It just would not come up at all. Today I had a similar situation when I had cover flow switched on in the finder while I was browsing an external hard drive that has 20 gigs of hundreds of subfolders inside hundreds of subfolders that contain thousands of photos. Cover flow could not handle this and it wouldn’t allow me to do antyhing else either. I had an application crunching data for the past 5 hours so restarting the machine was definitely not an option. I needed a way to cleanly kill Finder without destroying any other work going on. In situations like this you need to go beyond the GUI and directly to the terminal. Yes, I know, now that I am writing this article, I noticed that the “Force Quit” application actually has Finder as an option but being someone from a linux background I immediately go to Terminal for anything I need rather than look for GUI solutions.

What you need to do is find the PID (Process ID) of the application you need to kill. To do this, type the following in Terminal:

ps aux | grep Finder

The result of that command will be something like:

sergemadenian   131 97.1 25.9  1213744 542124   ??  R    Fri12PM  54:49.70 /System/Library/CoreServices/Finder.app/Contents/MacOS/Finder -psn_0_40970
sergemadenian  3932   0.1  0.0   590472    192 s000  R+   10:07PM   0:00.00 grep Finder

“ps aux” is the command that prints out all the currently running processes from all users. ” | grep Finder” will restrict the results of the “ps” command to show only the lines that contain the word “Finder”.

From the above result you can tell that the Finder application is question is the first line and I have set the PID in Bold and red “131″. You can also tell that this process is struggling because immediately after the pid we see the CPU and memory usage which in this case is “97.1 25.9″ (those are percentages).

Now that we know the PID (131) all you need to do is run the command:

kill -9 131

“-9″ tells the OS to kill immediately. That took care of the offending Finder window and I noticed that a new Finder process had been kicked off by the OS. If a new process had not automatically been kicked off, I would have had to start it manually by running the command that was running before which I’ve marked in blue and bold ”

Same process applies to any application including the Dock. All you need to do is find the specific PID by changing what you filter with grep. For the Dock as an example, you will need to run:

ps aux | grep Dock

Remember that the PID is not a universal number (that is your Finder application will not have 131, even my computer will have a different PID for Finder when I restart it) so you need to always find the unique PID running at the time.