one too many levels of indirection (from ks@purdue)
[unix-history] / usr / src / lib / libc / sys / vfork.2
CommitLineData
d6ee9320
KM
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.\"
eff6446c 5.\" @(#)vfork.2 6.2 (Berkeley) %G%
d6ee9320 6.\"
71fb3f26 7.TH VFORK 2 ""
d6ee9320
KM
8.UC 4
9.SH NAME
10vfork \- spawn new process in a virtual memory efficient way
11.SH SYNOPSIS
bf5bb190
KM
12.B pid = vfork()
13.br
14.B int pid;
d6ee9320
KM
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
bf5bb190 22.IR execve .
d6ee9320
KM
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
bf5bb190 28.IR execve (2)
d6ee9320
KM
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
eff6446c 42from the procedure that called
d6ee9320
KM
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
bf5bb190 52.IR execve ,
d6ee9320
KM
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.)
d6ee9320 62.SH SEE ALSO
bf5bb190 63fork(2), execve(2), sigvec(2), wait(2),
d6ee9320
KM
64.SH DIAGNOSTICS
65Same as for
66.IR fork .
67.SH BUGS
bf5bb190
KM
68This system call will be eliminated when proper system sharing
69mechanisms are implemented.
70Users should not depend on the memory
d6ee9320
KM
71sharing semantics of
72.I vfork
bf5bb190
KM
73as it will, in that case, be made synonymous to
74.IR fork .
d6ee9320
KM
75.PP
76To avoid a possible deadlock situation,
eff6446c 77processes that are children in the middle
d6ee9320
KM
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.