[TUHS] "Fork considered harmful"

Chris Hanson cmhanson at eschatologist.net
Fri Apr 12 09:37:52 AEST 2019


On Apr 10, 2019, at 4:06 PM, Richard Salz <rich.salz at gmail.com> wrote:
> 
> Any view on this? https://www.microsoft.com/en-us/research/publication/a-fork-in-the-road/

Quite correct in my experience.

The posix_spawn() API isn’t a panacea but (especially with a few *_np extensions) it’s much saner for large real-world applications that run a ton of subprocesses. I work on a large IDE which invokes compilers and such, and it makes a huge difference.

The biggest need for *_np extensions has been control over fd inheritance and chdir behavior. Otherwise a subprocess can wind up inheriting random or no fds from a multithreaded process (thanks to the race between setting up and finishing the call) and you need to use pthread_{chdir,fchdir}() or openat() to set the working directory in which the subprocess is launched.

  -- Chris



More information about the TUHS mailing list