shell程序中如何判断某个程序是否在运行?
请问shell程序中如何判断某个程序是否在运行? 譬如说查看终端窗口tyy进程ps -ax|grep tty #!/bin./sh
echo "Enter the program: "
read Enter
N=`ps -ax|grep -c $Enter`
if [ $N -eq 0 ]
then
echo "$Enter has't run!"
else
echo "$Enter running!"
fi
用这个试试!(没测试过!) 用这个会出问题,有时候
比如:
$ ps ax|grep phoenix
23896 ? S 0:00 /bin/sh /usr/local/phoenix/run-mozilla.sh /usr/local/
15712 pts/3 R 0:00 grep phoenix
$ ps ax|grep realplay
15956 pts/3 R 0:00 grep realplay
就算realplayer没有运行,得到的结果还是非空的
这个怎么办? top #!/bin./sh
echo "Enter the program: "
read Enter
N=`ps -ax|grep -c $Enter|grep -v "grep"`
if [ $N -eq 0 ]
then
echo "$Enter has't run!"
else
echo "$Enter running!"
fi
用这个试试! 我已经修改过!(没测试过!) #!/bin./sh
echo "Enter the program: "
read Enter
N=`ps -ax|grep -c $Enter|grep -v "grep"`
if [ $N -eq 0 ]
then
echo "$Enter has't run!"
else
echo "$Enter running!"
fi
用这个试试! 我已经修改过!(没测试过!)
这个就没问题了,呵呵
看了一下帮助,-v是选择不匹配的,呵呵
thanks:) 呵呵,当时没注意到,执行grep后,本身他还有一个grep进程的,所以#Enter这的变量还是有的,所以....
#!/bin./sh
echo "Enter the program: "
read Enter
N=`ps -ax|grep -c $Enter|grep -v "grep"`
if [ $N -eq 0 ]
then
echo "$Enter has't run!"
else
echo "$Enter running!"
fi
用这个试试! 我已经修改过!(没测试过!)
不错哦
#!/bin/sh
echo "Enter the program: "
read Enter
N=`ps -ax|grep -c $Enter|grep -v "grep"`
if [ $N -eq 0 ]
then
echo "$Enter has't run!"
else
echo "$Enter running!"
fi
用这个试试! 我已经修改过!(没测试过!)
不错哦
过奖了!多指教啊! 一个进程有多种状态,run or running more....... 一个进程有多种状态,run or running more.......
对,说的没错!
页:
[1]