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.