title: python - subprocess.Popen().pid return the pid of the parent script
body: <p>I am trying to run a Python script from another Python script, and getting its <code>pid</code> so I can kill it later.</p>
  
  <p>I tried <code>subprocess.Popen()</code> with argument <code>shell=True', but the</code>pid<code>attribute returns the</code>pid` of the parent script, so when I try to kill the subprocess, it kills the parent.</p>
  
  <p>Here is my code:</p>
  
  <pre class="lang-py prettyprint-override"><code>proc = subprocess.Popen(" python ./script.py", shell=True)
  pid_ = proc.pid
  .
  .
  .
  # later in my code
  
  os.system('kill -9 %s'%pid_)
  
  #IT KILLS THE PARENT :(
  </code></pre>