title: How to terminate process from Python using pid?
body: <p>I'm trying to write some short script in python which would start another python code in subprocess if is not already started else terminate terminal &amp; app (Linux).</p>
  
  <p>So it looks like:</p>
  
  <pre><code>#!/usr/bin/python
  from subprocess import Popen
  
  text_file = open(".proc", "rb")
  dat = text_file.read()
  text_file.close()
  
  def do(dat):
  
      text_file = open(".proc", "w")
      p = None
  
      if dat == "x" :
  
          p = Popen('python StripCore.py', shell=True)
          text_file.write( str( p.pid ) )
  
      else :
          text_file.write( "x" )
  
          p = # Assign process by pid / pid from int( dat )
          p.terminate()
  
      text_file.close()
  
  do( dat )
  </code></pre>
  
  <p>Have problem of lacking knowledge to name proces by pid which app reads from file <em>".proc"</em>.
  The other problem is that interpreter says that string named <em>dat</em> is not equal to <em>"x"</em> ??? What I've missed ?</p>