Kill Processes Using Wildcards with pkill in OS X

Oct 18, 2012 - 1 Comment

pkill

For anyone who uses the command line regularly, a new tool called pkill makes killing processes significantly easier in OS X 10.8 and later. 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.

At it’s most basic function, pkill can be used as follows:

pkill ApplicationName

For example, killing all processes belonging to “Safari”, including Safari Web Content processes, would be just a matter of typing:

pkill Safari

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:

pkill C*

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 OS X prior to Mountain Lion.

Enjoy this tip? Subscribe to the OSXDaily newsletter to get more of our great Apple tips, tricks, and important news delivered to your inbox! Enter your email address below:

Related articles:

Posted by: William Pearson in Command Line, Mac OS X, Tips & Tricks

One Comment

» Comments RSS Feed

  1. Marc says:

    Your wildcard examples suffer from a flaw… the shell will attempt to expand the wildcards before pkill sees them. take this example: pkill C*

    It will not work if the current working directory has any file that starts with a capital C. The shell will expand the wildcard expression and pkill will be given the names of the files in your current working directory that start with C, not the expression ‘C*’.

Leave a Reply

 

Shop for Apple & Mac Deals on Amazon.com

Subscribe to OSXDaily

Subscribe to RSS Subscribe to Twitter Feed Follow on Facebook Subscribe to eMail Updates