Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:0xSteph Pentest ai ProcessRegistry

From Leeroopedia
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

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")

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment