title: How can I check if a Unix process is running in Perl?
body: <p>In UNIX, I am checking to see if a process is up by executing the following command;</p>
  
  <p>E.g.</p>
  
  <pre><code>psg dtllst pe99
  </code></pre>
  
  <p>This returns the following output if the process is running;</p>
  
  <pre><code>UID    PID    PPID    C    STIME    TTY    TIME CMD
  pe99   1234   1       0 03:29:44    pts/8  0:01 dtllst pe99
  </code></pre>
  
  <p>Now in Perl, I want to be able to find out whether this process is up or not. So far I am doing the following</p>
  
  <pre><code>`my $checkProc = `psg dttlst | grep $myNode 2&gt;&amp;1`;`    #where $myNode is something like pe01 or pe02 or pe65 or pe99 etc...
  </code></pre>
  
  <p>Now after this I do the following to see if the above Perl command has returned what I am looking for to see if the process is up;</p>
  
  <pre><code>if ($checkProc =~ m/dtllst $myNode | $myNode/) {
      #yes, process is up
  } else {
      #no, process is down
  }
  </code></pre>
  
  <p>However this is not working - specifically, regardless of whether the UNIX process is alive or not, my code ALWAYS evaluates the if statement as true. I know this is wrong. 
  I have tried to escape the "$" character in the regex to see if this was the issue and I have also tried removing the Perl variables from within the regex altogether.</p>
  
  <p>What am I missing here? I know my regex is wrong somewhere :(</p>
  
  <p>Thanks</p>