#!/usr/bin/env python3

# Given a process ID, find the process group ID and
# then kill the entire process group.

import os
import signal
import sys

def kill_pg(pid):
   pgid = os.getpgid(pid)

   if not pgid:
      sys.stderr.write(
          "ERROR unable to find process group ID from PID: %d\n" % pid)
   else:
      os.killpg(pgid, signal.SIGKILL)

def usage():
   sys.stderr.write("Pass a process ID as the first argument\n")
   sys.exit(1)

if __name__ == '__main__':
   if len(sys.argv) < 2:
      usage()

   kill_pg(int(sys.argv[1]))
