Description
Follow-up to #19286 (raised in review: #19286 (comment)).
On POSIX, core::system::terminateProcessTree(pid) collects the descendants with getChildProcesses() while the root is alive, signals the root, and then signals each descendant by bare pid. Nothing pins those pids: if a descendant exits after it was listed and its pid is reused before the kill(), an unrelated process gets the signal. The window is short, and terminateChildProcesses(pid, signal) has always had the same one, but the Windows implementation goes to some length to rule this out (it holds a handle to every process it has validated before terminating any of them).
Options:
- Linux: open a pidfd (
pidfd_open, 5.3+) for each descendant while the tree is intact, confirm through/procthat the pidfd's process still has the expected parent, and signal throughpidfd_send_signal. A pidfd keeps referring to the same process, so its pid cannot be swapped underneath it. - macOS / elsewhere: no pidfd. Re-checking the parent pid just before
kill()narrows the window but cannot close it; a descendant whose parent was already signalled may have been reparented by then.
There is no production caller on POSIX today (the Quarto job's stop uses it on Windows only), so this matters once something on POSIX starts using it. terminateChildProcesses() could share whatever this ends up being.
Activity