-
Notifications
You must be signed in to change notification settings - Fork 1
Description
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.