title: Find PID of created PHP process in PHP
body: <p>I first execute the following command,</p>
  
  <pre><code> $retVal = proc_close(proc_open("rfcomm connect \/dev\/rfcomm0 &amp;&gt; /dev/null 2&gt; /dev/null &amp;", array(), $pipe));
  </code></pre>
  
  <p>I have to use proc_close right after proc_open or the command hangs my php page. Later on my script if I try to find out the PID of this background process I only get returned my grep request:</p>
  
  <pre><code>$val = shell_exec("ps aux | grep rfcomm0");
  </code></pre>
  
  <p>It only returns the process of my grep command:</p>
  
  <blockquote>
    <p>www-data 6412 0.0 0.3 2004 624 ? S 12:23 0:00 grep rfcomm0</p>
  </blockquote>
  
  <p>Now if I enter the exact same command from shell_exec into my SSH terminal on my server I get the following:</p>
  
  <pre><code>www-data  6047  0.0  0.3   1752   592 ?        S    12:10   0:00 rfcomm connect /dev/rfcomm0 
  root      6415  0.0  0.4   3532   804 pts/1    S+   12:27   0:00 grep rfcomm0
  </code></pre>
  
  <p>The first result is the PID I want. Is PHP unable to retrieve the PID of its own processes or is there another way to solve this mystery?</p>
  
  <p>Thanks!</p>