Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to kill all processes with the same name using OS X Terminal

Getting the following output from running this:

ps aux | grep Python 

Output:

user_name  84487   0.0  0.0        0      0   ??  Z    12:15PM   0:00.00 (Python) user_name  84535   0.0  0.0        0      0   ??  Z    12:16PM   0:00.00 (Python) 

I want to terminate all Python processes currently running on a machine....

like image 232
alphanumeric Avatar asked Mar 11 '14 19:03

alphanumeric


2 Answers

use pkill, with the -f option.

pkill -f python 

If you don't have pkill pre-installed (some osx's don't...), try proctools.

like image 195
shx2 Avatar answered Oct 14 '22 17:10

shx2


If you don't have pkill, you can try this:

ps aux | grep python | grep -v grep | awk '{print $2}' 

If that gives you the PIDs you want to kill, join that up with the kill command like this

kill $(ps aux | grep python | grep -v grep | awk '{print $2}') 

That says... kill all the PIDs that result from the command in parentheses.

like image 34
Mark Setchell Avatar answered Oct 14 '22 17:10

Mark Setchell