vfork instead of fork for fork+exec?

Charles Oliver Nutter charles.nutter at sun.com
Fri May 15 23:14:41 PDT 2009

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

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 

- Charlie

More information about the bsd-port-dev mailing list