Friday, October 24, 2014

Linux: Kill Processes With Specific Keyword

When we are going to kill a process with specific keyword, we can simply find the PID(process id) by command as follows (PID is always shown in the second column of the result):
ps aux | grep "keyword"

Then the process can be forcibly killed by:
kill -9 PID

This method works fine when there is only one or a few processes to be terminated. As the number of process grow larger and larger, it is too painful to do it manually. Consequently, we have to deal with it in some other way.

Note: All the solutions below will kill processes which is listed on the screen via command 'ps aux | grep "keyword"'.

Solution 1:
pgrep keyword | xargs kill -9

Solution 2:
ps aux | grep keyword | awk '{print $2}' | xargs kill -9

Solution 3:
kill -s 9 `pgrep keyword`

Solution 4:
pkill -9 keyword

Pick one that you're most comfortable with :)

© 2014-2017 jason4zhu.blogspot.com All Rights Reserved 
If transfering, please annotate the origin: Jason4Zhu

No comments:

Post a Comment