How to Kill All Processes with a Given Partial Name? [Closed]
I Want to Kill All Processes That I Get by: Ps Aux | Grep My_Pattern How to Do It? This Does Not Work: Pkill My_Pattern 3 14 Answers Use Pkill -F, Which...
I want to kill all processes that I get by:
ps aux | grep my_pattern
How to do it?
This does not work:
pkill my_pattern
14 Answers
Use pkill -f, which matches the pattern for any part of the command line
pkill -f my_pattern
Just in case it doesn't work, try to use this one as well:
pkill -9 -f my_pattern
Must Read
Kill all processes matching the string "myProcessName":
ps -ef | grep 'myProcessName' | grep -v grep | awk '{print $2}' | xargs -r kill -9
Source:
Why "ps pipe kill" from terminal is evil:
The Piping of integers you scraped from ps -ef to kill -9 is bad, and you should feel bad, doubly so if you're root or a user with elevated privileges, because it doesn't give your process a chance to cleanly shut down socket connections, clean up temp files, inform its children that it is going away or reset its terminal characteristics.
Instead send 15, and wait a second or two, and if that doesn't work, send 2, and if that doesn't work, send 1. If that doesn't, REMOVE THE BINARY because the program is badly behaved.
As a general principle we don't use Unix Railgun to trim the hedges.
Explanation of above command:
ps -ef produces a list of process id's on the computer visible to this user. The pipe grep filters that down for rows containing that string. The grep -v grep says don't match on the process itself doing the grepping. The pipe awk print says split the rows on default delimiter whitespace and filter to the second column which is our process id. The pipe xargs spins up a new process to send all those pid's to kill -9, ending them all.