Wednesday, July 8, 2015

Unix - Grep a process and kill all at once

Dear Reader,
Today I am writing how to find/grep a process and kill in Unix.
This is solely for my reference, so even if it is not useful for you, sorry for that.

//vi killProcess.sh

#Store All processes in ProcessFile.txt
exec ps -eaf | grep APPNAME | cut -c -135

ps -eaf | grep MY_PROCESS | awk '{print $2}' > ProcessFile.txt

while read line
do
    echo "Killing Process Id $line"
    kill -9 $line
done < ProcessFile.txt

echo 'Executing command after killing processes: ps -eaf | grep APPNAME'
exec ps -eaf | grep APPNAME | cut -c -135


No comments:

Post a Comment