vfork instead of fork for fork+exec?
Dmitry Samersoff
dms at samersoff.net
Sat May 16 06:12:41 PDT 2009
Charles,
On BSD vfork() stops parent process until child exited or call exec.
It's not acceptable in multithreaded environment.
Also real performance difference between fork() and vfork() is not huge
because all modern kernels use copy-on-write and copy only in-kernel
page table, not pages it self.
-Dmitry
Charles Oliver Nutter wrote:
> Hi all!
>
> I'm trying to hack together a raw fork+exec for JRuby users that allows
> them to launch subprocesses with the same stdin/stdout, like for REPLs
> that want to launch a functional 'vim' subprocess. While trying to
> investigate some inconsistencies in using FFI to do fork+exec on Darwin,
> I came across the vfork function:
>
> Vfork() can be used to create new processes without fully copying
> the address space of the old process,
> which is horrendously inefficient in a paged environment. It is
> useful when the purpose of fork(2)
> would have been to create a new system context for an execve.
> Vfork() differs from fork in that the
> child borrows the parent's memory and thread of control until a
> call to execve(2) or an exit (either by
> a call to exit(2) or abnormally.) The parent process is suspended
> while the child is using its
> resources.
>
> I noticed this isn't used in the BSD port, which uses either fork1 or
> __sys_fork. Perhaps this would be a faster fork to use for
> process-launching?
>
> - Charlie
>
--
Dmitry Samersoff
dms at samersoff.net, http://devnull.samersoff.net
* There will come soft rains ...
More information about the bsd-port-dev
mailing list