vfork instead of fork for fork+exec?
Martin Buchholz
martinrb at google.com
Fri May 15 23:44:25 PDT 2009
jdk7 includes subprocess I/O redirection.
I thought a lot about vfork in solaris or linux,
but never tried to use it because it's just too scary
to use in a multithreaded program.
I think there must be comments of mine in the
Sun bug database which you should be able to search.
Martin
On Fri, May 15, 2009 at 23:14, Charles Oliver Nutter
<charles.nutter at sun.com> 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
>
>
More information about the bsd-port-dev
mailing list