Kill Processes Using Wildcards with pkill in Mac OS X
For anyone who uses the command line regularly, a new tool called pkill makes killing processes significantly easier in modern releases of Mac OS and Mac OS X. Improving on the standard kill command, pkill easily supports wildcards, making it easy to terminate all processes belonging to a match or even a specific user.
Using pkill to Kill Processes on Mac OS
At it’s most basic function, pkill can be used as follows:
For example, killing all processes belonging to “Safari”, including Safari Web Content processes, would be just a matter of typing:
Killing Processes with pkill and Wildcards
But pkill is perhaps best used with uid flags and wildcards, for example you can kill all processes that start with the letter “C” using the following:
Processes belonging to a single user can also be terminated easily with the -U flag and additional details:
pkill -U username ProcessName
For example, you could kill every process belonging to user Will with the following;
sudo pkill -u Will *
Assuming the specified user is logged in, all apps running by that user will be killed. However, the user will not be logged out and core system processes pertaining to that user will remain intact.
Review the manual page for pkill for more uses and flags, and remember that average Mac users will be better served managing tasks with Activity Monitor instead. pkill is not available to Mac OS or OS X prior to Mountain Lion.