Comment by olliej

4 years ago

On Darwin fork() doesn't necessarily give you a complete environment - the cloned process is essentially only intended for a few basic operations prior to calling exec()

So it isn't just windows and linux having a different way, Darwin goes its own way as well :D

That said, if you read the paper it details all the known problems of fork:

* It isn't thread safe

* It doesn't compose - every library on the address space must support fork

* It breaks basic security features - ASLR being the most obvious one, but there are sandbox issues (Darwin), pledges (BSD), capabilities (Fuchsia)

The paper also details the myriad performance problems of the API.

fork/exec is also very slow due to the need to duplicate enough OS data structures to support the forked child despite it not being useful in the general case to separate these. Even POSIX recognizes this and specifies posix_spawn() which is faster than fork/exec on all POSIX environments.

posix_spawn is just a wrapper around vfork and exec. And crucially, you have it in addition to them, not instead of them, because sometimes it can't do what you need.