title: To get Parent and ChildProcess ID from process ID in Python
body: <p>I am trying to get the <code>ppid</code> of the process that I want.</p>
  
  <p>I used following code to get the pid</p>
  
  <pre><code>proc=subprocess.Popen('ps -ae | grep ruby', shell=True, stdout=subprocess.PIPE, )
  output=proc.communicate()[0]
  str = output.split()
  </code></pre>
  
  <p>Now in the <code>str[0]</code>, I have the pid of the process say ruby, I want to get the parent process ID <code>ppid</code> and child process ID of the same process.</p>
  
  <p>I need this solution to be run on <code>Solaris as well as Red Hat Enterprise Linux</code> 6.0</p>
  
  <p>Is there any way to get that like <code>getppid()</code> and <code>getchildid()</code>? Or do I need to do it by <code>grep</code> command again and splitting?</p>