Avoid signaling recycled process groups

Merged
AU
3mo ago
+96-33

After the direct child has been reaped, stop trusting its cached numeric process-group id because the kernel may reuse it. Teardown now signals only a foreground group freshly observed through the retained PTY. Includes regression coverage for an unrelated cached group and for reaping a distinct foreground job after the leader has genuinely exited.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.


Summary by cubic

Prevents teardown from signaling a recycled process group after the child is reaped. Now we only stop the foreground group read from the retained PTY, avoiding signals to unrelated jobs.

  • Bug Fixes
    • Stop trusting cached process_group_id once the child is reaped; use fresh foreground_process_group_id from the PTY.
    • Switch to killProcessGroupWithTimeouts to target only the active foreground group.
    • Add regression tests for ignoring stale groups and for killing a distinct foreground job after the leader exits.

Summary by CodeRabbit

  • Bug Fixes
    • Improved subprocess cleanup after a process exits.
    • Prevented teardown from targeting stale process information, reducing the risk of terminating unrelated foreground processes.
    • Ensured remaining subprocesses are consistently cleaned up when their leader exits.