Classes
PIDManager
Manage PID files for process tracking and recovery.
Features:
- Detect stale processes
- Graceful …
PIDManager
Manage PID files for process tracking and recovery.
Features:
- Detect stale processes
- Graceful process termination
- PID file validation
- Cross-platform support
Methods 6
get_pid_file
staticmethod
Get the PID file path for a project.
get_pid_file
staticmethod def get_pid_file(project_root: Path) -> Path
Get the PID file path for a project.
Parameters 1
project_root |
Path |
Root directory of Bengal project |
Returns
Path to PID file in .bengal/ directoryPath
—
is_bengal_process
staticmethod
Check if PID is actually a Bengal serve process.
Uses psutil if available for …
is_bengal_process
staticmethod def is_bengal_process(pid: int) -> bool
Check if PID is actually a Bengal serve process.
Uses psutil if available for accurate process name checking. Falls back to simple existence check if psutil is not installed.
Parameters 1
pid |
int |
Process ID to check |
Returns
True if process is Bengal serve, False otherwisebool
—
check_stale_pid
staticmethod
Check for stale PID file and return PID if found.
A stale PID file indicates a…
check_stale_pid
staticmethod def check_stale_pid(pid_file: Path) -> int | None
Check for stale PID file and return PID if found.
A stale PID file indicates a previous server instance that didn't shut down cleanly (crash, kill -9, power loss, etc.).
This method:
- Reads the PID file
- Checks if the process exists
- Verifies it's actually a Bengal process
- Returns the PID if stale, None otherwise
Invalid or empty PID files are automatically cleaned up.
Parameters 1
pid_file |
Path |
Path to PID file |
Returns
PID of stale process, or None if no stale processint | None
—
kill_stale_process
staticmethod
Gracefully kill a stale process.
Tries SIGTERM first (graceful), then SIGKILL …
kill_stale_process
staticmethod def kill_stale_process(pid: int, timeout: float = 5.0) -> bool
Gracefully kill a stale process.
Tries SIGTERM first (graceful), then SIGKILL if needed.
Parameters 2
pid |
int |
Process ID to kill |
timeout |
float |
Seconds to wait for graceful shutdown |
Returns
True if process was killed, False otherwisebool
—
write_pid_file
staticmethod
Write current process PID to file.
Uses atomic write to ensure the PID file is…
write_pid_file
staticmethod def write_pid_file(pid_file: Path) -> None
Write current process PID to file.
Uses atomic write to ensure the PID file is crash-safe.
Parameters 1
pid_file |
Path |
Path to PID file |
get_process_on_port
staticmethod
Get the PID of process listening on a port.
Uses lsof to find which process is…
get_process_on_port
staticmethod def get_process_on_port(port: int) -> int | None
Get the PID of process listening on a port.
Uses lsof to find which process is listening on a port. This is useful for detecting port conflicts.
Parameters 1
port |
int |
Port number to check |
Returns
PID if found, None otherwiseint | None
—