How to kill multiple processes

killprocess-managementps

to find the PID of the process to kill use :

pgrep <process command>

I then use the kill command to kill the PID returned by pgrep <process command>

kill <PID>

Can these commands be combined into one so can kill the PID or PID's returned by pgrep <process command> ? Or is there a method kill multiple processes by command name ?

Something like : kill(pgrep <name of process>)

Best Answer

You can use pkill:

pkill httpd

You may also want to use process substitution(although this isn't as clear):

kill $(pgrep command)

And you may want to use xargs:

pgrep command | xargs kill
Related Question