BSD 3 development
[unix-history] / usr / man / man2 / vfork.2
CommitLineData
2ced1824
BJ
1.UC
2.TH VFORK 2
3.SH NAME
4vfork \- spawn new process in a virtual memory efficient way
5.SH SYNOPSIS
6\fBvfork()\fR
7.SH DESCRIPTION
8.I Vfork
9can be used to create new processes without fully copying the address
10space of the old process, which is horrendously inefficient in a paged
11environment. It is useful when the purpose of
12.I fork
13(2) would have been to create a new system context for an
14.I exec.
15.I Vfork
16differs from fork in that the parent's memory and thread of control run in
17the child's system context till a call to
18.I exec
19(2) or an exit
20(either by a call to
21.I exit
22(2) or abnormally.)
23The parent's process slot is suspended while it runs in the child's.
24.I Vfork
25returns 0 in the child's context and (later) the pid of the child in
26the parents context.
27.PP
28.I Vfork
29can normally be used just like
30.I fork.
31It does not work, however, to return while running in the childs context
32from the procedure which called
33.I vfork
34since the eventual return from
35.I vfork
36would then return to a no longer existant stack frame.
37Be careful, also, to call
38.I _exit
39rather than
40.I exit
41if you can't
42.I exec,
43since
44.I exit
45will flush and close standard I/O channels, and thereby mess up the
46parent processes standard I/O data structures. (Even with
47.I fork
48it is wrong to call
49.I exit
50since buffered data would then be flushed twice.)
51.SH SEE ALSO
52fork(2), exec(2), wait(2),
53.SH DIAGNOSTICS
54Same as for fork.
55.SH BUGS
56Would be unnecessary if
57.I fork
58were implemented by a mechanism similar to copy-on-write.
59The current system does not support this mechanism, however, necessitating
60.I vfork.