one too many levels of indirection (from ks@purdue)
[unix-history] / usr / src / lib / libc / sys / vfork.2
... / ...
CommitLineData
1.\" Copyright (c) 1980 Regents of the University of California.
2.\" All rights reserved. The Berkeley software License Agreement
3.\" specifies the terms and conditions for redistribution.
4.\"
5.\" @(#)vfork.2 6.2 (Berkeley) %G%
6.\"
7.TH VFORK 2 ""
8.UC 4
9.SH NAME
10vfork \- spawn new process in a virtual memory efficient way
11.SH SYNOPSIS
12.B pid = vfork()
13.br
14.B int pid;
15.SH DESCRIPTION
16.I Vfork
17can be used to create new processes without fully copying the address
18space of the old process, which is horrendously inefficient in a paged
19environment. It is useful when the purpose of
20.IR fork (2)
21would have been to create a new system context for an
22.IR execve .
23.I Vfork
24differs from
25.I fork
26in that the child borrows the parent's memory and thread of
27control until a call to
28.IR execve (2)
29or an exit (either by a call to
30.IR exit (2)
31or abnormally.)
32The parent process is suspended while the child is using its resources.
33.PP
34.I Vfork
35returns 0 in the child's context and (later) the pid of the child in
36the parent's context.
37.PP
38.I Vfork
39can normally be used just like
40.I fork.
41It does not work, however, to return while running in the childs context
42from the procedure that called
43.I vfork
44since the eventual return from
45.I vfork
46would then return to a no longer existent stack frame.
47Be careful, also, to call
48.I _exit
49rather than
50.I exit
51if you can't
52.IR execve ,
53since
54.I exit
55will flush and close standard I/O channels, and thereby mess up the
56parent processes standard I/O data structures.
57(Even with
58.I fork
59it is wrong to call
60.I exit
61since buffered data would then be flushed twice.)
62.SH SEE ALSO
63fork(2), execve(2), sigvec(2), wait(2),
64.SH DIAGNOSTICS
65Same as for
66.IR fork .
67.SH BUGS
68This system call will be eliminated when proper system sharing
69mechanisms are implemented.
70Users should not depend on the memory
71sharing semantics of
72.I vfork
73as it will, in that case, be made synonymous to
74.IR fork .
75.PP
76To avoid a possible deadlock situation,
77processes that are children in the middle
78of a
79.I vfork
80are never sent SIGTTOU or SIGTTIN signals; rather,
81output or
82.IR ioctl s
83are allowed
84and input attempts result in an end-of-file indication.