ServerMonitor / dev /tests /web /fake /taskkill
mchuca's picture
Server Monitor: six editions (C++/Qt, Python, web for Linux and Windows), requirements and developer kit
bad179a
Raw History Blame Contribute Delete
622 Bytes
#!/usr/bin/env python3
"""Review stand-in for taskkill.exe: "taskkill /PID <n> /T /F" ends the process <n> and everything below it (like /T on Windows)."""
import os, signal, sys
args = sys.argv[1:]
pid = int(args[args.index('/PID') + 1])
kids = {}
for d in os.listdir('/proc'):
if d.isdigit():
try: kids.setdefault(int(open(f'/proc/{d}/stat').read().rsplit(')', 1)[1].split()[1]), []).append(int(d))
except OSError: pass
def tree(p): return [p] + [x for k in kids.get(p, []) for x in tree(k)]
for p in tree(pid) if '/T' in args else [pid]:
try: os.kill(p, signal.SIGKILL)
except OSError: pass