#52 Killing Processes by Name
Linux and some Unixes have a very helpful command called killall, which allows you to kill all running applications that match a specified pattern. It can be quite helpful when you want to kill nine mingetty daemons, or even just to send a SIGHUP signal to xinetd to prompt it to reread its configuration file. Systems that don't have killall can emulate it in a shell script, built around ps for identification of matching processes and kill to send the specified signal.
The tricky part of the script is that the output format from ps varies significantly from OS to OS. For example, consider how differently Mac OS X and Red Hat Linux show running processes in the default ps output:
OSX $ ps PID TT STAT TIME COMMAND ...
Get Wicked Cool Shell Scripts now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.