posix_spawn can take care of many common cases today.
posix_spawn can take care of many common cases today.
CLONE_VFORK means that the parent process is suspended until the child either exits or execs, and CLONE_VM means that no copy-on-write happens - the child has full read/write access to the original memory space until it execs (or exits). In the child, posix_spawn is careful to work within temporary memory so it doesn't overwrite anything that the parent process might care about, including global variables etc. Then once exec succeeds (or fails, and the process exits), posix_spawn in the parent cleans up that temporary memory.
This means that posix_spawn doesn't require any copy-on-write support from the kernel. Or in other words, there's no posix_spawn syscall and there shouldn't be because it's a library function, but there is a vfork syscall.