title: How to Terminate Multiprocessing Parent Process?
body: <p>How can I get my Child process to terminate the Parent process?</p>
  
  <p>I was thinking something along the lines of...</p>
  
  <p>Child gets Parent Process's PID and terminates the parent using <code>psutil</code></p>
  
  <p>Here's my code </p>
  
  <pre><code>from multiprocessing import Process, Value
  import keyboard
  import sys
  
  def KeyboardScan(v):
      Paused = False
      while True:
          if keyboard.is_pressed('x'):
              v.value = 1
              print("Child Terminate")
              sys.exit()
      #Child process's code
  
  if __name__ == "__main__":
      val = Value('i', 0)
      p = Process(target=KeyboardScan, args=(val,))
      p.start()
  
      #Parent process's code
  </code></pre>
  
  <p>So if the key <code>x</code> is pressed, the Child should terminate the Parent and itself.</p>
  
  <p>In this code the <code>value</code> exists only because originally I had a while loop in my Parent process to check for the value. If the value is 1 then it performs a <code>sys.exit()</code> on the Parent process.</p>
  
  <p>But I'm trying to avoid using this method.</p>
  
  <p>Any suggestions?</p>