VFORK(2)

NAME
vfork - spawn new process in a virtual memory efficient way

SYNOPSIS
vfork()

DESCRIPTION
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 exec. Vfork differs from fork in that the parent's memory and thread of control run in the child's system context till a call to exec (2) or an exit (either by a call to exit (2) or abnormally.) The parent's process slot is suspended while it runs in the child's. Vfork returns 0 in the child's context and (later) the pid of the child in the parents context.

Vfork can normally be used just like fork. It does not work, however, to return while running in the childs context from the procedure which called vfork since the eventual return from vfork would then return to a no longer existant stack frame. Be careful, also, to call _exit rather than exit if you can't exec, since exit will flush and close standard I/O channels, and thereby mess up the parent processes standard I/O data structures. (Even with fork it is wrong to call exit since buffered data would then be flushed twice.)

SEE ALSO
fork(2), exec(2), wait(2),

DIAGNOSTICS
Same as for fork.

BUGS
Would be unnecessary if fork were implemented by a mechanism similar to copy-on-write. The current system does not support this mechanism, however, necessitating vfork.