SysProc
SysProc class.
Wrapper of psutil.Process class.
This class that only exposes necessary functionalities to easily manage shell processes.
Initialize self. See help(type(self)) for accurate signature.
psutil.Process | Nonebool - FalseReturn all the chlidren of process recursively.
listProcessboolboolKill the process and all its children.
If the process was started with a process group (start_new_session=True), sends SIGTERM to the entire process group first for graceful shutdown, waits briefly, then sends SIGKILL to any survivors. Otherwise, falls back to killing each child individually.
Get process statistics
dictWait for a process PID to terminate
AnyAnySysProcFind all processes carrying marker_env_var in their environment.
The app layer sets marker_env_var on every app child (and thus its whole inherited
tree), so this locates app processes regardless of which port they ended up on.
strtupleAnySysProcKill app child processes left over from a previous, uncleanly-stopped server run.
Apps are spawned in their own process group (start_new_session=True), so a hard server stop (SIGKILL, crash, OOM, closing the terminal) leaves them running with no one tracking them. On the next boot they must be reaped explicitly, before any port allocation, or their RAM accumulates run after run (see issue #97).
Detection is by the marker_env_var environment variable. This catches orphans
regardless of which port they ended up on. When reading process environments is denied
(AccessDenied), falls back to a port-band sweep so the reaper still works under
stricter permissions.
This kills EVERY marked process, so it is only safe at boot, when no app is tracked yet. For mid-session use, find the marked processes and kill only the untracked ones.
strrangelistFind any process with a LISTEN socket on port and kill its entire process group.
Killing the process group (SIGKILL via killpg) takes down the listener plus its supervisor and siblings atomically — necessary for runners like Reflex where the listener's parent would otherwise respawn a replacement between our kill and the next bind attempt.
Returns the list of PIDs that were targeted (may be empty). If the OS denies access to enumerate sockets, logs a warning and returns [].
intlistSIGKILL the process groups of the given pids, deduplicating groups.
liststrlist