VFORK(2)
NAME
vfork − spawn a new process in a more efficient way
USAGE
pid = vfork() int pid;
DESCRIPTION
Vfork creates new processes without fully copying the address space of the old process. This conserves resources in a paged environment. Vfork is primarily useful when the purpose of fork(2) is to create a new system context for an execve(2). Vfork differs from fork in that the child borrows the parent’s memory and thread of control until a call to execve or an exit (either by a call to exit(2) or abnormally.) The parent process is suspended while the child is using its resources.
Vfork returns zero in the child’s context and (later) the PID of the child in the parent’s context.
Vfork can normally be used just like fork. However, it is illegal to return from the procedure that called vfork while running in the child process, since by so doing, vfork would be attempting to return to a non-existent stack frame. Be careful, also, to call _exit rather than exit if you can’t execve, since exit will flush and close standard I/O channels, and thereby affect the parent process’s standard I/O data structures. (Even with fork, it is better not to call exit since buffered data is then flushed twice.)
NOTES
In a future release, this system call may be eliminated in favor of a more effective process creation mechanism.
To avoid possible deadlocks, processes that are children in the middle of a vfork are never sent SIGTTOU or SIGTTIN signals; rather, output or ioctls are allowed, and input attempts result in an end-of-file indication.
RETURN VALUE
Upon successful completion, vfork returns zero to the child process and returns the child’s process ID to the parent process. Otherwise, -1 is returned to the parent process, no child process is created, and errno is set to indicate the error.
ERRORS
Vfork will fail and no child process will be created if one or more of the following is true:
[EAGAIN] The system-imposed limit on the total number of processes under execution would be exceeded.
[EAGAIN] The system-imposed limit on the total number of processes under execution by a single user would be exceeded.