Batch kill program processes containing a keyword under Linux

Source: Internet
Author: User

Sometimes, because of special circumstances, you need to kill all the processes under Linux that match a certain condition, and you cannot use Killall to directly kill all the running processes contained in a process name (we may just need to kill one of these or run a process with the specified parameter command). PS, grep, cut and kill work together.

OK, here is a specific reference:

Ps-ef|grep local=no|grep-v grep|cut-c 9-15|xargs kill-9

Is it convenient to run this command to kill all the processes that contain the keyword "local=no"?

Here is a brief description of this command:

Pipe symbol "|" Used to separate two commands, the output from the left command of the pipe character is entered as the command to the right of the pipe.

"Ps-ef" is a command to view all processes in Linux. The retrieved process is then entered as the next command "grep local=no".

The output of "grep local=no" is that all processes that contain the keyword "Local=no".

Grep-v grep removes the process that contains the keyword "grep" in the listed process.

The Cut-c 9-15″ is the 9th character to the 15th character of the input line, which is exactly the process number PID.

The Xargs command in Xargs Kill-9″ is used to take the output (PID) of the preceding command as a parameter to the Kill-9″ command and execute the command. "Kill-9″ will forcibly kill the specified process.

In other similar cases, you just need to modify the keyword section in grep local=no.

Another way to use awk

PS x|grep gas|grep-v grep |awk ' {print $} ' |xargs kill-9

PS: Transfer from http://www.cnblogs.com/lichkingct/archive/2010/08/27/1810463.html

Batch kill program processes containing a keyword under Linux

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.