Script

Superkill - A Quickie Script for Killing All Instances of an Application

Evolution crashed on me this morning and I kept getting an error message: "Evolution appears to have exited unexpectedly...". Every time I started the application, it provided that message then locked so I went to my trusty command line. I did a ps -ef | grep evo and saw that several evolution-based processes were running:
steven    7885     1  0 09:57 ?        00:00:08 evolution --component=mail
steven    7894     1  0 09:57 ?        00:00:00 /usr/lib/evolution/evolution-data-server-2.22
steven    7918     1  0 09:57 ?        00:00:00 /usr/lib/evolution/2.22/evolution-exchange-storage
steven    7931     1  0 09:57 ?        00:00:00 /usr/lib/evolution/2.22/evolution-alarm-notify 
steven   11346  7715  0 11:12 pts/1    00:00:00 grep evo
I then proceeded to kill each process manually. It's only 4 but it was enough to bring out my inner programmer and solve a repetitive task programatically. So I decided to add a couple more pipes. I looked at the results from the grep'd ps and noticed that all process IDs are in character slots 10-14 so I cut -c 10-14 the processes that were piped in. That printed out as expected so I fed that to kill via xargs and, voila!, all those processes were killed. Not content to have to type all the pipes every time I wanted to do it, I threw the pipe in a BASH script that I lovingly call 'superkill' and take the first argument as the string to grep and kill the returned processes. The code is below:
#!/bin/bash

prog=$1

#echo ${prog}
ps -ef | grep ${prog} | cut -c 10-14 | xargs kill
Simple enough but quite powerful. I then threw the script in my /usr/bin directory so my PATH would pick it up. Now I can just superkill evolution (sounds like a creationist book, I know) and have all the processes ended. Here is the file. Just extract it (tar xzvf superkill.tar.gz) and put the resulting file in your /usr/bin directory. Then superkill away! Of course this code comes with no warranty and you assume all risks. Before you run the script you may want to call a ps -ef | grep <processname> before doing superkill <processname> so you make sure there are no unexpected results. I could echo the resulting process and ask for confirmation, I suppose. Hold for that version (depends if I get feedback it works well enough for my purposes).

Latest Video


only search Coder's Wasteland
Powered by Drupal, an open source content management system

Digg this