In this blog, we will discuss killing the multiple processes in Linux with grep command. There are some use cases where you need to kill processes with matched regex using the grep.
For this, we have deployed the two different Prometheus server processes on Linux. And we will kill those processes with a combination of grep and kill command.
Listing the processes:



The command is used for listing up processes is following:
ps -ef | grep "prometheus"
To list all processes process id’s with the name “Prometheus” following command will be used:
$ for pid in $(ps -ef | grep "prometheus" | awk '{print $2}'); do echo $pid; done 40010 39992 40159
It will list all processes.
To kill all processes with the name “Prometheus” following command will be used:
$ for pid in $(ps -ef | grep "prometheus" | awk '{print $2}'); do kill $pid; done
It will kill all the processes with the name Prometheus. If you have any questions about this 1m read then please let us know.
You can check our other blogs related with Kubernetes pod and Prometheus metrics. If you dont know linux please check this blog from open source community.