CentOS 7 pidof -x did not work
<p>I have one CentOS 7 Server VM. In this VM I have <code>Apache Apollo</code> installed</p>

<p>I just created a script given below</p>

<pre><code>#!/bin/bash

if pidof -x "apollo" &gt;/dev/null; then
echo "Apollo MQTT is Running."
exit 0
else
echo "Apollo MQTT is Stopped."
exit 2
fi
</code></pre>

<p>Using above script I want to check apollo service is running or not. But when i run this script using below command</p>

<pre><code>sh filename
</code></pre>

<p>It gives the output <code>Apollo MQTT is Stopped</code> when servce is running.</p>

<p>When I run below command</p>

<pre><code>ps -ef | grep apollo
</code></pre>

<p>It gives the below output</p>

<pre><code>root       8647      1  3 10:49 pts/0    00:00:55 java -ea -server -Xmx1G -XX:+HeapDumpOnOutOfMemoryError -XX:-UseBiasedLocking -Dcom.sun.management.jmxremote -Dapollo.home=/opt/apollo -Dapollo.base=/var/lib/mqtt -classpath /opt/apollo/lib/apollo-boot.jar org.apache.activemq.apollo.boot.Apollo /var/lib/mqtt/lib\;/opt/apollo/lib org.apache.activemq.apollo.cli.Apollo run
root       9426   8233  0 11:15 pts/0    00:00:00 grep --color=auto apollo
</code></pre>