[Review, 3rd] SF-0007: Subprocess

I realize that the review period is over, but I just hit a limitation of Foundation.Process Windows that also exists in Subprocess and which I’d like to share for consideration:

When launching a process that itself might launch subprocesses, it is possible to terminate the entire process tree on Posix platforms using send(signal: .kill, toProcessGroup: true). However, there is no way to terminate an entire process tree on Windows. As far as I could tell, supporting this would require the process to be associated to a job object with JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE during process creation (Destroying all child processes (and grandchildren) when the parent exits - The Old New Thing) – as a disclaimer, I have not tried had the chance to verify this approach myself.

For context why I hit this: SourceKit-LSP launches subprocesses to perform background indexing. When it shuts down, it should ensure that it doesn’t leave any orphan processes behind, and defaults to killing/terminating (on Posix vs Windows resp.) unresponsive subprocesses. But processes like swift-build might have spawned their own children, which would not be affected by their parent’s termination, leaving them running parentless.

5 Likes