Implementation:0xSteph Pentest ai ProcessRegistry
| Knowledge Sources | |
|---|---|
| Domains | Process_Management, Subprocess, Kill_Safety |
| Last Updated | 2026-10-23 00:00 GMT |
Overview
Concrete tool for tracking live security tool subprocesses with kill capability, provided by the pentest-ai engine.
Description
The ProcessRegistry class is a live process registry for security tool subprocesses. Every SecurityTool.execute() that spawns an asyncio subprocess registers its PID, tool name, and target. Operators can list running processes (ptai ps), kill one (ptai kill <pid>), or query the registry from MCP clients. Uses a plain dict with a threading.Lock for mutation. Reads return a snapshot copy for safe iteration.
Usage
Import this module when you need to track or kill running tool subprocesses. Used by the agent loop and MCP server.
Code Reference
Source Location
- Repository: 0xSteph_Pentest_ai
- File: engine/process_registry.py
- Lines: 1-155
Signature
@dataclass
class ProcessRecord:
pid: int
tool: str
target: str
started_at: float
engagement_id: str = ""
cmd: str = ""
class ProcessRegistry:
def register(self, pid: int, tool: str, target: str, *, engagement_id: str = "", cmd: str = "") -> None: ...
def unregister(self, pid: int) -> None: ...
def list_all(self) -> list[ProcessRecord]: ...
def kill(self, pid: int) -> bool: ...
def kill_all(self) -> int: ...
Import
from engine.process_registry import ProcessRegistry, ProcessRecord
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| pid | int | Yes | Process ID to register/kill |
| tool | str | Yes | Tool name |
| target | str | Yes | Target being scanned |
Outputs
| Name | Type | Description |
|---|---|---|
| list_all | list[ProcessRecord] | Snapshot of all running processes |
| kill | bool | True if process was killed |
| kill_all | int | Number of processes killed |
Usage Examples
Track and Kill Processes
from engine.process_registry import ProcessRegistry
registry = ProcessRegistry()
registry.register(pid=12345, tool="nmap", target="10.0.0.1", engagement_id="eng-1")
# List running processes
for p in registry.list_all():
print(f" PID {p.pid}: {p.tool} → {p.target} ({p.runtime_seconds():.0f}s)")
# Kill a specific process
registry.kill(12345)
# Kill all running processes
killed = registry.kill_all()
print(f"Killed {killed} processes")