r/cpp • u/SatadeepDasgupta • Jul 03 '26
Windows doesn't have fork(), so I faked copy-on-write with VirtualProtect + exception handling to snapshot an in-memory KV store
0
Upvotes
r/cpp • u/SatadeepDasgupta • Jul 03 '26
View all comments
Show parent comment
2
u/RogerV Jul 07 '26
there is ton of truth on that one - in the child process right after fork there are a vast number of things that a program might do before doing an ex3c of the.target executable. might prepare a pseudo terminal PTY master-slave and dup2 all the stdio descriptors onto the slave descriptor. Or might apply a CPU mask to where the child process will be allowed to execute on some subset of CPU cores. Or set a network namespace context and create a veth pair network interface where the child process will be executing in a network sandbox and only permitted the Beth interface for its networking connectivity. And there is the choice of whether to execute as the real or effective UID/GID.
I could go on and on listing the kinds of techniques that are commonly used in launching child processes via fork()
Far from being a relic of a bygone era, fork() is still one of the crucial API of Linux/Unixiy programming. It’s bread and butter for architecting multi-tenancy sandboxing applications. But clone(), which fork is built on per Linux, is likewise crucial as its even more versatile for dialing in what is actually inherited by the child - I.e., how heavy weight it is.