on *nix at times I miss a “kill by name ” utilitly, my life mostly involves running a java task, which takes a bit too long and then I want to terminate it. Here is a simple Kill by name implementation
killByName() {
args=(“$@”)
processLine=`ps -ef |grep ${args[0]} |grep ${args[1]}`
processToKill=`echo $processLine |awk ‘{print $2}’ `
kill -9 $processToKill
}
Add this to your bashrc file and we can kill programs by their name. For example if I spawned a process with
java com.pramati.DoesNotTerminate
I can kill it with
killByName java DoesNotTerminate
All this little function does is look for processes that have java and DoesNotTerminate, gets their pid using awk and runs kill with the awk output as xargs.
Have you used the unix killall command? I believe it is similar, but may be more scalable.
killall is better, but more complicated, this is a simple search by anything that you remember about your process and kill it sort of thing.
correction
kill `pidof PROCESSNAME`
PROCESSNAME is name of the process.
Note the backquotes, not really visible in comment box.
is what I wanted to type. This comment box strips out the “less than” and “greater than” symbols with anything else in between them