0

如果两个进程未运行,我如何检查“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

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

谢谢

4

2 回答 2

2
if [ $(ps aux | grep -E "(processName1|processName2)" | grep -v grep | wc -l) -eq 0 ]
then
    echo "not running"
fi
于 2013-04-04T18:00:23.420 回答
1
ps -aux |grep -v <process name> 

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

于 2013-04-04T16:57:19.300 回答