Remix.run Logo
dmitrygr a day ago

fork() was always very restricted in when it could be used and really dangerous even then. It was made for a world where process == thread, and since that ceased to be true it's been a large footgun. Use spawn if you need to launch a process, reconsider your life if your immediate post-fork() syscall is not exec()

edelbitter a day ago | parent [-]

But what would the equivalent "do the expensive preparation 1 time, then re-use copy-on-write memory N times" pattern look like, after reconsidering my life?

zbentley 21 hours ago | parent | next [-]

It looks like threads and a copy-on-write data structure or memory mapping.

cestith a day ago | parent | prev [-]

The manpage suggests if you need the child to be the same as the parent to exec a copy of the parent in the child right after forking.

oasisaimlessly a day ago | parent [-]

This doesn't allow reusing initialization work via CoW mappings (like GP was asking about).

cestith 21 hours ago | parent [-]

This is an artifact of doing as the platform is documented to work. You can do what the man page says, or you can do the opposite. The whole article is about how forking on macOS is troublesome.