search for and kill a running process

One of the most frustrating things is trying to uninstall an app from a remote terminal without knowing what is actually running on the computer. Inevitably, the app you are trying to remove  will be open and since processes are running, you risk damaging the OS or at the very least not being able to completely rid the computer of it without a restart or two. And of course, it can sometimes prove difficult to find and kill those processes without the aid of the GUI Activity Monitor.

I developed a more elegant way that I use in conjunction with Casper Remote to search for and destroy known running processes. For this example we are removing Suitcase Fusion 2 and/or 3, two pieces of software that I loathe and are in wide use at some remote sites in my company.

The find/kill process involves the use of the ps command and diving into the executables within the application packages themselves. For example, To find the Suitcase Fusion 2 process we need to look at the executable inside the Suitcase Fusion 2 package itself (the first two lines should show as one line in terminal):

sfClientApp=$(ps -ax | grep -i "Suitcase Fusion Fusion 2" | grep -vi "grep" | awk ' { print $1 } ')
if [ -n "$sfClientApp" ]; then
sudo kill -s KILL "$sfClientApp" > /dev/null 2>&1
echo "Done"

What this piece of code does is to first output all processes belonging to anyone on the Mac, then filter that with grep  for the executable within Suitcase Fusion 2. It assigns the process number (given by the awk command) if found to sfClientApp, otherwise nothing is assigned. If $sfClientApp is not nothing, it issues a kill command to that process ID, and voila! No more Suitcase Fusion 2 process!

There is a lot more to removing Suitcase Fusion 2 OR 3 than just that one command, but it does prove a failsafe way to find and terminate any process save ones run through Rosetta (e.g.: any MS Office 2004 app). For those interested, I’ve linked to the code used to find and remove Suitcase Fusion 2 AND 3 here:

About this entry