Kill process by name instead of PID

Jun 24, '03 06:58:00AM

Contributed by: Splatta

Right on the heels of the pidof script comes pkill. This command has started to show up in the latest versions of Linux and Solaris, so here's a script to get the same functionality under OS X:

#!/bin/sh

for X in `ps acx | grep -i $1 | awk {'print $1'}`; do
  kill $X;
done
Put this script in /usr/bin/pkill, chmod it (chmod 755 /usr/bin/pkill), and use it like this:

pkill iTunes or pkill itunes -- this script is case-insensitive.

Comments (10)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20030620102036392