import sys
import os
import signal


if sys.platform.startswith("win"):
  def taskkill(pid):
    os.system('taskkill /F /PID {:d} /T >NUL 2>NUL'.format(pid))
else:  # POSIX
  def taskkill(pid):
    os.kill(pid, signal.SIGTERM)

import sys
import os
import signal


if sys.platform.startswith("win"):
  def taskkill(pid):
    os.system('taskkill /F /PID {:d} /T >NUL 2>NUL'.format(pid))
else:  # POSIX
  import psutil
  def taskkill(pid):
    parent = psutil.Process(pid)
    for child in parent.children(recursive=True):
      child.kill()
    parent.kill()

Kill child processes as well as shell process
Kill child processes as well as shell process

  import sys
  import os
  import signal
  
  
  if sys.platform.startswith("win"):
    def taskkill(pid):
      os.system('taskkill /F /PID {:d} /T >NUL 2>NUL'.format(pid))
  else:  # POSIX
+   import psutil
    def taskkill(pid):
-     os.kill(pid, signal.SIGTERM)
+     parent = psutil.Process(pid)
+     for child in parent.children(recursive=True):
+       child.kill()
+     parent.kill()
  
Kill child processes as well as shell process
## Code Before:
import sys
import os
import signal


if sys.platform.startswith("win"):
  def taskkill(pid):
    os.system('taskkill /F /PID {:d} /T >NUL 2>NUL'.format(pid))
else:  # POSIX
  def taskkill(pid):
    os.kill(pid, signal.SIGTERM)

## Instruction:
Kill child processes as well as shell process
## Code After:
import sys
import os
import signal


if sys.platform.startswith("win"):
  def taskkill(pid):
    os.system('taskkill /F /PID {:d} /T >NUL 2>NUL'.format(pid))
else:  # POSIX
  import psutil
  def taskkill(pid):
    parent = psutil.Process(pid)
    for child in parent.children(recursive=True):
      child.kill()
    parent.kill()
