shell高手请进,救命!
应用背景:在终端上运行A程序,进程A fork出A1和B1两个进程,
这段shell目的是要从/test/list文件夹中读取以终端名命名的文件(如:tty1a、tty2a),其中每个文件中的内容对应为在相应终端上运行的A程序的进程号(父进程),然后kill掉父进程A及其子进程A1和B1。
我目前遇到的问题是:该段代码运行到
pid1=`cat $uptty/$ans`
ps -ef|awk -F' ' -v ppid=$pid1 -e '$3 == ppid {print "kill -9 "$2}'
kill -9 $pid1
部分时,有时正常,有时则不正常(尤其是放在程序循环中区做时尤为明显),表现为运行A程序的终端“死”在那里,该shell程序停滞没有反应,感觉似乎与CPU的运行时间片分配有关,请教各位高手到底是怎么回事?该如何解决?谢谢!
uptty=/test/list
if [ "$1" ] #参数$1为终端名.
then
ans="$1"
else
echo "请输入终端号: \c"
read ans
fi
while [ $ans ]
do
if [ ! -s $uptty/$ans ]
then
dispactive
else
echo "正在处理...\c"
#
# get the pid from the active file and kill the process.
#
pid1=`cat $uptty/$ans`
ps -ef|awk -F' ' -v ppid=$pid1 -e '$3 == ppid {print "kill -9 "$2}'
kill -9 $pid1
echo "..\c"
……