Its a simple script I created ..
It helps me Kill all PIDs ( Processes IDs ) .. that has the given name as part of its name
Here is the script
#################################################
# !/bin/bash
# kills any process ,, with the passed string matchs its name
#################################################
#################################################
#function the takes number of arguments ,, with the PIDs ..
#like 2342 2342 2234 separated by spaces. assuming each
#number as a PID
#################################################
function killPid(){
echo;
echo “Killing processes for program : ‘ $1′ ….”;
echo ‘—————————————————-’;
shift ;
eval last=\${$#} ;
for pid in $*; do
#-o $# -lt 4
if [ $pid -eq $last ];then
break;
fi
# KILL THE PID
kill -9 $pid;
# Store the return value of the kill command …
result=$?;
# If Process was Killed Successfully
# tell That it was Killed Successfully
[ $result ] && echo “PID: $pid was Killed Successfully !”;
# If Process was not Killed Successfully
# tell That it was not Killed !
[ $result ] || echo “PID: $pid was NOT Killed !”;
shift ; # shift arguments 1 place left
done
echo ‘—————————————————-’;
return 0;
}
while [ $# -gt 0 ]; do
#Get the process line that has the PID
processes=”`ps ux | \
sed -ne “/$1/s/$USER [[:space:]]\+\([0-9]\+\).*/\1/p”`”;
killPid $1 $processes;
echo ‘—————————————————-’;
shift ; # shift arguments 1 place left
done
Technorati Tags: bash, shell, linux, kill, script, process, part