The vfork() function creates new processes without fully copying the address space of the old process. This function is useful in instances where the purpose of a fork(2) operation would be to
create a new system context for an execve() operation (see exec(2)).
Unlike with the fork() function, the child process borrows the parent's memory and thread of control until a call to execve() or an exit (either abnormally or by a call to _exit() (see exit(2)). The parent process is suspended while the child is using its resources.
In a multithreaded application, vfork() borrows only the thread of control that called vfork() in the parent; that is, the child contains only one thread. The use of vfork() in multithreaded applications, however, is not advised.
The vfork() function can normally be used the same way as fork(). The procedure that called vfork(), however, should not return while running in the child's context, since the eventual return from vfork() would be to a stack
frame that no longer exists. The _exit() function should be used in favor of exit(3C) if unable to perform an execve() operation,
since exit() will flush and close standard I/O channels, and thereby corrupt the parent process's standard I/O data structures. The _exit() function should be used even with fork() to avoid flushing the buffered data twice.
|