日期:2014-05-16  浏览次数:20725 次

linux 程序启动和关闭的脚本
大家好,我在写一个linux程序的启动和关闭脚本时,运行过程中,程序能正常run和shutdown,可是总出现如下提示:
kill: (20146) - 没有那个进程,得怎么修改才能不会出现这个提示。

脚本内容如下:
run.sh内容
ulimit -c unlimited
PIDPROC=`ps -ef | grep asiserver | awk '{print $2}'`
for PID in $PIDPROC
do
if kill -9 $PID
then echo "process asiserver($PID) was force stopped at " `date`>>log/run.txt
fi
done
sleep 3
nohup ./asiserver >out.txt 2>&1 &
echo "uasserver start at"`date` >>log/run.txt
exit

shutdown.sh内容
#! /bin/sh

PIDPROC=`ps -ef | grep asiserver | awk '{print $2}'`
for PID in $PIDPROC
do
if kill -9 $PID
then echo "process asiserver($PID) was force stopped at " `date` >>./log/run.txt 
fi
done



运行过程如下:
>>./run.sh 
./run.sh: line 5: kill: (20146) - 没有那个进程

>>./p
root 20149 1 1 11:37 pts/0 00:00:00 ./asiserver
root 20159 20157 0 11:37 pts/0 00:00:00 grep asiserver

>>./shutdown.sh 
./shutdown.sh: line 10: kill: (20163) - 没有那个进程

------解决方案--------------------
PIDPROC=`ps -ef | grep asiserver | awk '{print $2}'`
改成
PIDPROC=`ps -ef |grep asiserver |grep -v 'grep'| awk '{print $2}'`
试试