A process is a symbol of the execution of a program in the computer, and the corresponding process terminates when the program is finished executing. But in reality many processes do not die at the end of the execution of the program, so they become zombies, and a small number of zombies do not affect the performance of the server, but no server can provide good performance in many processes.
Sometimes, because of some special circumstances, you need to kill all processes under Linux that match a certain condition, and you can't use Killall to kill all of the running processes that a process name contains (we may just have to kill one or the process of running a specified parameter command), and we need to use PS, grep, cut and kill operate together.
Look at the process first (take PHP for example):
PS Ef|grep php
Snapshot2
View the number of processes
PS Ef|grep php|wc-l
Kill the process
Ps-ef|grep php-fpm|grep-v grep|cut-c 9-15|xargs kill-9
Batch kills the process that contains the keyword "php-fpm".
"Ps-ef"--View all processes
"Grep php-fpm"--Lists all processes that contain the keyword "PHP-FPM"
grep-v grep-Removes processes that contain keyword "grep" in the listed process (because the grep process we generated in the previous step also contains keywords)
"Cut-c 9-15″--intercepts the 9th character of the input line to the 15th character, which happens to be the process number PID
The Xargs Kill-9″--xargs command is used to take the output (PID) of the previous command as an argument to the Kill-9″ command and execute the command. "Kill-9″ will be forced to kill the specified process.
In other similar cases, just modify the keyword section of the "grep local=no".
Another way to use awk
PS x|grep gas|grep-v grep |awk ' {print $} ' |xargs kill-9