检查两个进程是否未在shell脚本中运行

时间:2013-04-04 16:53:31

标签: shell

如果两个进程没有运行,如何检查“if”条件?

我用过

if [ `pgrep <process name>`] does not work with ot without square brackets
using ps -aux |grep <process name> in if condition does not work, since every time 
grep <process name>
is up and it will always pass

任何人都有任何好的建议,我可以检查是否只需要两个进程“没有”运行

谢谢

2 个答案:

答案 0 :(得分:2)

if [ $(ps aux | grep -E "(processName1|processName2)" | grep -v grep | wc -l) -eq 0 ]
then
    echo "not running"
fi

答案 1 :(得分:1)

ps -aux |grep -v <process name> 

-v是'反向匹配',IOW,当您要查找的项目不匹配时它返回成功