title: Check if a subprocess is running in Linux using Python
body: <p>I have an environment variable that allows a suite of applications to run under certain conditions, and the applications cannot run with the environment variable off.</p>
  
  <p>My python script uses</p>
  
  <pre><code>p = subprocess.Popen(cmdStr3,stdout=subprocess.PIPE,stderr=subprocess.STDOUT)
  </code></pre>
  
  <p>to open the subprocess.</p>
  
  <p>To test if the application is running, I have tried</p>
  
  <pre><code>try:
      os.kill(pid, 0)
      return True
  except OSError:
      return False
  </code></pre>
  
  <p>and also checking <code>p.returncode</code>. However, these always return true, because even if the application doesn't pull up on the screen, there are mini processes of ~1 MB that still run without the application fully running, so the os sees these and returns true. Is there a way around this?</p>
  
  <p>Another issue is that <code>os.kill</code> doesn't work, the only way I have found to terminate the application is <code>os.killpg</code> at the end.</p>
  
  <p>What I've learned from the comments is that what actually happens is that the subprocess I call is a starter that calls a child which is another application. My subprocess always runs, but with the environment variable off, the child application does not run. Is there a way to see if the child is running?</p>