Skip to content

ptrace(2) support for pstop(1)/prun(1) #49

@basil

Description

@basil

Currently pstop(1) and prun(1) use SIGSTOP/SIGCONT to stop and resume target processes, with pstop(1) polling /proc/$PID/stat in an exponential-backoff loop to confirm the process has actually reached the stopped state before returning. This approach has two drawbacks: the polling loop is inherently racy and wasteful, and SIGSTOP can be observed by the target's parent via waitpid(2), which may confuse job-control-aware shells or process supervisors. Switching to PTRACE_ATTACH (if the user has permission) would let pstop(1) block until the target is confirmed stopped without polling, and PTRACE_DETACH with a SIGSTOP or SIGCONT argument would give prun(1) atomic detach-and-resume semantics. This would also let both tools detect and handle the "already ptrace-stopped by another debugger" case up front via the EPERM errno from PTRACE_ATTACH, rather than relying on the current best-effort /proc state check that is subject to TOCTOU races.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions