benzy 发表于 2003-4-19 11:55:01

shell程序中如何判断某个程序是否在运行?

请问shell程序中如何判断某个程序是否在运行?

skynew 发表于 2003-4-19 14:54:06

譬如说查看终端窗口tyy进程
ps -ax|grep tty

bixuan 发表于 2003-4-19 18:13:34

#!/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
用这个试试!(没测试过!)

benzy 发表于 2003-4-20 01:15:12

用这个会出问题,有时候
比如:
$ 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没有运行,得到的结果还是非空的
这个怎么办?

qinghongcao 发表于 2003-4-20 13:04:57

top

bixuan 发表于 2003-4-20 17:56:09

#!/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
用这个试试! 我已经修改过!(没测试过!)

benzy 发表于 2003-4-21 01:14:14

#!/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:)

bixuan 发表于 2003-4-21 08:44:10

呵呵,当时没注意到,执行grep后,本身他还有一个grep进程的,所以#Enter这的变量还是有的,所以....

keven 发表于 2003-4-22 15:29:51



#!/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
用这个试试! 我已经修改过!(没测试过!)

不错哦

bixuan 发表于 2003-4-22 15:55:48



#!/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
用这个试试! 我已经修改过!(没测试过!)

不错哦
过奖了!多指教啊!

powerme 发表于 2003-5-6 22:30:05

一个进程有多种状态,run or running more.......

bixuan 发表于 2003-5-7 09:14:33

一个进程有多种状态,run or running more.......
对,说的没错!
页: [1]
查看完整版本: shell程序中如何判断某个程序是否在运行?