shell - How to kill all processes matching a name?

ID : 10145

viewed : 34

Tags : shellcommand-linekillshell

Top 5 Answer for shell - How to kill all processes matching a name?

vote vote

98

From man 1 pkill

-f     The pattern is normally only matched against the process name.        When -f is set, the full command line is used. 

Which means, for example, if we see these lines in ps aux:

apache   24268  0.0  2.6 388152 27116 ?        S    Jun13   0:10 /usr/sbin/httpd apache   24272  0.0  2.6 387944 27104 ?        S    Jun13   0:09 /usr/sbin/httpd apache   24319  0.0  2.6 387884 27316 ?        S    Jun15   0:04 /usr/sbin/httpd 

We can kill them all using the pkill -f option:

pkill -f httpd 
vote vote

81

ps aux | grep -ie amarok | awk '{print $2}' | xargs kill -9  

xargs(1): xargs -- construct argument list(s) and execute utility. Helpful when you want to pipe in arguments to something like kill or ls or so on.

vote vote

73

use pgrep

kill -9 $(pgrep amarok) 
vote vote

62

The safe way to do this is:

pkill -f amarok 
vote vote

59

I think this command killall is exactly what you need. The command is described as "kill processes by name".It's easy to use.For example

killall chrome 

This command will kill all process of Chrome.Here is a link about killall command

http://linux.about.com/library/cmd/blcmdl1_killall.htm

Hope this command could help you.

Top 3 video Explaining shell - How to kill all processes matching a name?

Related QUESTION?