4 ms·
because posix_spawn() in linux often calls fork(). I just looked at the manpage now and it says under some conditions it'd call vfork() instead, but I don't rem
by khc 9y ago
because posix_spawn() in linux often calls fork(). I just looked at the manpage now and it says under some conditions it'd call vfork() instead, but I don't remember that being the case when I last looked at this (6-7 years ago?)
- noselasd 9y agoNowadays, posix_spawn() calls clone() on linux, with the CLONE_VM flag, behaving much like vfork() as far as I can tell. That means the child and parent process shares the memory (until exec() is performed). Especially if the parent process is multi-threaded this avoids a whole lot of pagefaults that would occur if using fork() when another thread touches memory, possibly triggering a lot of copy-on-writes in the time window between calling fork() and the child calling exec() Code: https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/spawni.c;h=6b699a46dd404aa39d49349d09a191909e3e93ab;hb=65f6c94e682e3c21bde4c3aea74011c00d41ac04#l352 https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/uni...