Lately I’ve been working with a few java applications and decided I’d really like a more convenient way of killing the processes. What I wanted was essentially:

$ jkill {name} {signal}

With little help from a few blog posts, I decided on the following, which I like quite a bit:

for pid in `ps -Ao pid,command | grep java | grep $1 | sed "s/^[ ]*//" | cut -d\  -f1`;
  ps -p$pid --no-header -f
  kill -@2 $pid