On Linux and the other POSIX hosts, clone is the host's fork: the child has a copy
of the guest's memory, registers and descriptor table, and its descriptors share the
host's open files with the parent's, as Linux shares them. CLONE_VFORK (vfork,
posix_spawn) waits in the parent until the child has exec'd or exited, as the kernel
does. The child has a copy of the memory rather than sharing it, which is all a vfork
child may rely on before execve. execve loads the new program into the same host
process, keeping its pid, its descriptors without the close-on-exec ones, and the
signals it ignores. #! scripts run their interpreter, found through the sysroot.
wait4, waitid, kill, tgkill, process groups and sessions are the host's, with
signal numbers and wait statuses translated. A guest that ignores a signal has the
host ignore it (SIGPIPE, SIGCHLD, SIGINT). A signal whose default action ends a
process ends the host process with the same signal, so a parent sees what it would on
Linux.
A fork from a thread copies that thread alone, as on Linux. Every lock of the runtime (descriptors, memory map, JIT, futexes, process) is held across the host's fork, and the child makes each one again, since its thread has a new id.
Windows has no fork. A vfork child runs in its parent's process (with its own
descriptor table, registers and signal state) until it execs. Then another copy of
this runtime starts the program, adopting the child's descriptors as inherited
handles (--fd=N:HANDLE, --cwd), and the parent goes on from its clone. A child
that exits before its exec leaves a status for wait4. An execve outside a vfork
child starts the new program the same way and ends with its status. A plain fork
returns ENOSYS there. The Windows paths compile with llvm-mingw but have not been run.
Made from docs/platforms/gnuabi/README.md at 69237645142c. GPL-3.0-or-later.