diff --git a/agent-node/src/agent_node/main.py b/agent-node/src/agent_node/main.py index 2f894e1..7f35cb4 100644 --- a/agent-node/src/agent_node/main.py +++ b/agent-node/src/agent_node/main.py @@ -100,6 +100,19 @@ print(f"[*] Cleaning up orphaned agent instance (PID {pid})...") try: p = psutil.Process(pid) + + # First, mercilessly slaughter all child processes (e.g. spawned PTY shells) + try: + children = p.children(recursive=True) + for child in children: + try: + child.kill() + except (psutil.NoSuchProcess, psutil.AccessDenied): + pass + except (psutil.NoSuchProcess, psutil.AccessDenied): + pass + + # Then terminate the parent p.terminate() try: p.wait(timeout=2)