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