我试图在CentOS和Oracle Linux over shell命令中检查pmon进程是否正在运行。我用下面的命令。
在CentOS:
ps -e | grep pmon;echo $?
输出
61577 ? 00:00:00 ora_pmon_orcl
0
但是,在Oracle Linux中:
ps -e | grep pmon;echo $?
输出
1
我无法理解他们为什么表现不同。 我可以获得一个可以在两个操作系统上运行的命令,如下所示
1 output for process not running
0 output for process running
答案 0 :(得分:1)
编辑:正如Vatine和Dipak所建议的那样 试试这个
ps -ef|grep [p]mon|wc -l|awk '{if ($1 != 0) print "0"; else print "1";}'
如果进程未运行,它将返回1
,如果正在运行则返回0
。