Multiple PIDs being stored in PID file
<p>I have a System V init script I've developed that starts a Java program. For some reason whenever the PID file gets created, it contains multiple PIDs instead of one.</p>

<p>Here's the relevant code that starts the service and writes to the PID file:</p>

<pre><code>daemon --pidfile=$pidfile "$JAVA_CMD &amp;" &gt;&gt; $logfile 2&gt;&amp;1
RETVAL=$?
usleep 500000

if [ $RETVAL -eq 0 ]; then
    touch "$lock"

    PID=$(ps aux | grep -vE 'grep|runuser|bash' | grep &lt;myservice&gt; | awk '{print $2}')

    echo $PID &gt; $pidfile
</code></pre>

<p>When I test the <code>ps aux...</code> command manually, a single line returns. When running as a script, it appears that this call is returning multiple PIDs.</p>

<p>Example contents in the PID file: <code>16601 16602 16609 16619 16690</code>. <code>16619</code> is the actual process ID found when manually running the <code>ps aux...</code> command mentioned above.</p>