Skip to content

fix: use PR_SET_PDEATHSIG so to ensure child processes are killed in a timely manner - #1626

Merged
bolinfest merged 1 commit into
mainfrom
pr1625
Jul 22, 2025
Merged

bolinfest merged 1 commit into
mainfrom
pr1625

Conversation

@bolinfest

@bolinfest bolinfest commented Jul 19, 2025 •

Copy link
Copy Markdown
Collaborator

Some users have reported issues where child processes are not cleaned up after Codex exits (e.g., #1570).

This is generally a tricky issue on operating systems: if a parent process receives SIGKILL, then it terminates immediately and cannot communicate with the child.

It only helps on Linux, but this PR introduces the use of prctl(2) so that if the parent process dies, SIGTERM will be delivered to the child process. Whereas previously, I believe that if Codex spawned a long-running process (like tsc --watch) and the Codex process received SIGKILL, the tsc --watch process would be reparented to the init process and would never be killed. Now with the use of prctl(2), the tsc --watch process should receive SIGTERM in that scenario.

We still need to come up with a solution for macOS. I've started to look at launchd, but I'm researching a number of options.

@bolinfest bolinfest added the code-review Issues relating to code reviews performed by codex label Jul 20, 2025
@github-actions github-actions Bot added codex-review-in-progress and removed code-review Issues relating to code reviews performed by codex labels Jul 20, 2025
@github-actions

Copy link
Copy Markdown
Contributor

Summary

This PR adds a Linux-only pre_exec hook that calls prctl(PR_SET_PDEATHSIG, SIGTERM) so any child processes spawned via the shell tool are automatically terminated when the Codex parent dies. A new libc dependency is introduced to support the system calls.

Review

Looks solid and solves the orphan-process issue in a straightforward way. A few minor nits:

  • Great to see the code behind cfg(target_os = "linux"); no impact on macOS/Windows builds.
  • Consider a short unit / integration test (even a doc comment) explaining the race-condition check with getppid().
  • Cargo.lock is updated correctly; CI should still pass.

Overall, happy with the change – just the small doc/test tweak and we’re good to merge!


View workflow run

@bolinfest
bolinfest merged commit d516548 into main Jul 22, 2025
@bolinfest
bolinfest deleted the pr1625 branch July 22, 2025 07:41
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 22, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants