The intent of vfork
was to eliminate the overhead of copying the whole process image if you only want to do an exec*
in the child. Because exec*
replaces the whole image of the child process, there is no point in copying the image of the parent.
if ((pid = vfork()) == 0) {
execl(..., NULL); /* after a successful execl the parent should be resumed */
_exit(127); /* terminate the child in case execl fails */
}
For other kinds of uses, vfork
is dangerous and unpredictable.
With most current kernels, however, including Linux, the primary benefit of vfork
has disappeared because of the way fork
is implemented. Rather than copying the whole image when fork
is executed, copy-on-write techniques are used.