#!/bin/sh
kill_with_proc_name () {
echo "-----------------------------------------------------------------\n"
echo "the name of proc you wish to kill : $1\n"
echo "-----------------------------------------------------------------\n"
echo "all procs as follow:\n"
ps -axu |awk '{print $2 , $11}' |grep $1
echo "-----------------------------------------------------------------\n"
#awk pid and proc name
pid=$(ps -axu |awk '{print $2 , $11}' |grep $1|awk '{print $1}')
echo "proc pid:$pid"
echo "-----------------------------------------------------------------\n"
# read -p "Enter the row number of which you want(1,2,3...) line: " proc_line_num
# echo "kill $proc_line_num now......."
# pid=$(ps -axu |grep $1 |grep -vE "$0|grep" |awk '{print $2}'|awk -v line="$proc_line_num" 'NR==line')
# echo "-----------------------------------------------------------------\n"
echo "I will kill $pid now......."
if [ -z $pid ]
then
echo "return with reason: no proc name with $1"
return
else
kill $pid
fi
}
#main()
if [ -z $1 ]
then
echo "[Error:] sorry \$1 is empty. \n please enter your proc name after './kill.sh' "
return
else
# echo "\$1 is $1"
kill_with_proc_name $1
ps_info=$(ps -axu |awk '{print $2 , $11}' |grep $1)
if [ -z $ps_info ]
then
echo "done!"
fi
fi