Comment by jepler
4 years ago
fork was one heck of a great mistake.
fork gives you multiprocessing, in which you set up a computational environment then create copies of it as needed (e.g., up to the processor parallelism available) to do more work in less time, and without the need to copy or lock data that is independently mutated by each fork. This is a powerful paradigm when there's little need for communication between distinct environments after the initial set-up (collating output may have its challenges, though)
fork+exec gives you spawn. Last I knew, process creation on Linux with fork+exec is faster than process creation on Windows anyway, so, y'know, what-ever.
on the other hand, sometimes (albeit rarely) you need to do specific handling after fork but before exec. posix_spawn, somewhat modeled after windows spawn I gather, lets you do specific limited actions. I don't know the state of affairs now, but many years ago the Python implementation of popen() had to spawn a specific "popen helper program" to perform the necessary file descriptor manipulations; the same sorts of hassles would exist if you were restricted to posix_spawn but needed to do some action that can't be represented as a file action or a spawn attribute.
No comments yet
Contribute on Hacker News ↗