1VFORK(2) System Calls Manual VFORK(2)
2
3
4
6 vfork - spawn new process in a virtual memory efficient way
7
9 pid = vfork()
10 int pid;
11
13 Vfork can be used to create new processes without fully copying the
14 address space of the old process, which is horrendously inefficient in
15 a paged environment. It is useful when the purpose of fork(2) would
16 have been to create a new system context for an execve. Vfork differs
17 from fork in that the child borrows the parent's memory and thread of
18 control until a call to execve(2) or an exit (either by a call to
19 exit(2) or abnormally.) The parent process is suspended while the
20 child is using its resources.
21
22 Vfork returns 0 in the child's context and (later) the pid of the child
23 in the parent's context.
24
25 Vfork can normally be used just like fork. It does not work, however,
26 to return while running in the childs context from the procedure that
27 called vfork since the eventual return from vfork would then return to
28 a no longer existent stack frame. Be careful, also, to call _exit
29 rather than exit if you can't execve, since exit will flush and close
30 standard I/O channels, and thereby mess up the parent processes stan‐
31 dard I/O data structures. (Even with fork it is wrong to call exit
32 since buffered data would then be flushed twice.)
33
35 fork(2), execve(2), sigvec(2), wait(2),
36
38 Same as for fork.
39
41 This system call will be eliminated when proper system sharing mecha‐
42 nisms are implemented. Users should not depend on the memory sharing
43 semantics of vfork as it will, in that case, be made synonymous to
44 fork.
45
46 To avoid a possible deadlock situation, processes that are children in
47 the middle of a vfork are never sent SIGTTOU or SIGTTIN signals;
48 rather, output or ioctls are allowed and input attempts result in an
49 end-of-file indication.
50
51
52
534th Berkeley Distribution June 30, 1985 VFORK(2)