title: How to check if a specific executable has a live process
body: <p>I want to write a script that checks periodically if a specific executable has a live process, something like this:</p>
  
  <pre class="lang-none prettyprint-override"><code>psping [-c ###] [-t ###] [-u user-name] exe-name
  -c - limit amount of pings, Default is infinite
  -t - define alternative timeout in seconds, Default is 1 sec
  -u - define user to check process for. The default is ANY user.
  </code></pre>
  
  <p>For example, <code>psping java</code> will list all processes that are currently invoked by the <code>java</code> command.</p>
  
  <p>The main goal is to count and echo the number of live processes for a user, whose executable file is <code>exe-name</code>, <code>java</code> in the above example.</p>
  
  <p>I wrote a function:</p>
  
  <pre><code>perform_ping(){
  
        ps aux | grep "${EXE_NAME}" | awk '{print $2}' | while read PID
           do
             echo $PID # -&gt; This will echo the correct PID
  
             # How to find if this PID was executed by ${EXE_NAME}
           done
      fi
      sleep 1
  }
  </code></pre>
  
  <p>I'm having a hard time figuring out how to check if a specific executable file has a live process.</p>