bash find and kill processes

A shell script wants your job

Today while I was working I saw that one of the machines very cruel lagna. Enter in it look a hell of a lot of zombie nabl″skal cron processes (rough around 50-60). There was no way to kill them all with killall so I had to do a little more literate solution to the problem – to start a clutter 猛击 script to find and kill processes. 50-Tina PID-not write easy by hand :D. The script for a minute and scratched it's hyped rudimentary but still deserves attention 🙂

At its base is sitting the conveyor belt

ps ax | grep -v grep | grep process_name | awk '{print $1}')

Here we get a list of all PID-s of the process that should kilnem as grep is ruled out from this list. As we have already listed the things become easy everything is rotated in a for. Here's the final result


PR=$(ps ax | grep -v grep | grep process_name | awk '{print $1}')

for PID in $PR
echo "$PID will be killed"
kill -9 $PID

Can be “tuned” as the name is taken as the argument after the script name and thus called as executable binary. However, it is not very good practice to have many such frequent cases 😀 but it never hurt to be protected from any šitni

Enhanced by Zemanta

leave a reply

Your email address will not be published. Required fields are marked *

anti SPAM *