Kill a process tree (including grandchildren) with signal "sig" and return a (gone, still_alive) tuple. "on_terminate", if specified, is a callabck function which is called as soon as a child terminates.
(pid, sig=signal.SIGTERM, include_parent=True,
timeout=None, on_terminate=None)
| 46 | |
| 47 | |
| 48 | def kill_proc(pid, sig=signal.SIGTERM, include_parent=True, |
| 49 | timeout=None, on_terminate=None): |
| 50 | """Kill a process tree (including grandchildren) with signal |
| 51 | "sig" and return a (gone, still_alive) tuple. |
| 52 | "on_terminate", if specified, is a callabck function which is |
| 53 | called as soon as a child terminates. |
| 54 | """ |
| 55 | if pid == os.getpid(): |
| 56 | raise RuntimeError("I refuse to kill myself") |
| 57 | parent = psutil.Process(pid) |
| 58 | parent.send_signal(sig) |
| 59 | |
| 60 | |
| 61 | def get_all_procs(): |