1 .\" Copyright (c) 1999 Andries Brouwer (aeb@cwi.nl), 1 Nov 1999
3 .\" Permission is granted to make and distribute verbatim copies of this
4 .\" manual provided the copyright notice and this permission notice are
5 .\" preserved on all copies.
7 .\" Permission is granted to copy and distribute modified versions of this
8 .\" manual under the conditions for verbatim copying, provided that the
9 .\" entire resulting derived work is distributed under the terms of a
10 .\" permission notice identical to this one.
12 .\" Since the Linux kernel and libraries are constantly changing, this
13 .\" manual page may be incorrect or out-of-date. The author(s) assume no
14 .\" responsibility for errors or omissions, or for damages resulting from
15 .\" the use of the information contained herein. The author(s) may not
16 .\" have taken the same level of care in the production of this manual,
17 .\" which is licensed free of charge, as they might when working
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" 1999-11-10: Merged text taken from the page contributed by
24 .\" Reed H. Petty (rhp@draper.net)
26 .TH VFORK 2 1999-11-01 "Linux 2.2.0" "Linux Programmer's Manual"
28 vfork \- create a child process and block parent
30 .B #include <sys/types.h>
32 .B #include <unistd.h>
35 .SH "STANDARD DESCRIPTION"
36 (From SUSv2 / POSIX draft.)
39 function has the same effect as
41 except that the behaviour is undefined if the process created by
43 either modifies any data other than a variable of type
45 used to store the return value from
47 or returns from the function in which
49 was called, or calls any other function before successfully calling
54 .SH "LINUX DESCRIPTION"
58 creates a child process of the calling process.
59 For details and return value and errors, see
65 It is used to create new processes without copying the page tables of
66 the parent process. It may be useful in performance sensitive applications
67 where a child will be created which then immediately issues an
73 in that the parent is suspended until the child makes a call to
77 The child shares all memory with its parent, including the stack, until
79 is issued by the child. The child must not return from the
80 current function or call
85 Signal handlers are inherited, but not shared. Signals to the parent
86 arrive after the child releases the parent's memory.
87 .SH "HISTORIC DESCRIPTION"
90 is implemented using copy-on-write pages, so the only penalty incurred by
92 is the time and memory required to duplicate the parent's page tables,
93 and to create a unique task structure for the child.
94 However, in the bad old days a
96 would require making a complete copy of the caller's data space,
97 often needlessly, since usually immediately afterwards an
99 is done. Thus, for greater efficiency, BSD introduced the
101 system call, that did not fully copy the address space of
102 the parent process, but borrowed the parent's memory and thread
103 of control until a call to
105 or an exit occurred. The parent process was suspended while the
106 child was using its resources.
109 was tricky: for example, not modifying data
110 in the parent process depended on knowing which variables are
113 It is rather unfortunate that Linux revived this spectre from the past.
114 The BSD manpage states:
115 "This system call will be eliminated when proper system sharing mechanisms
116 are implemented. Users should not depend on the memory sharing semantics of
118 as it will, in that case, be made synonymous to
122 Formally speaking, the standard description given above does not allow
127 might fail, and then what happens is undefined.
129 Details of the signal handling are obscure and differ between systems.
130 The BSD manpage states:
131 "To avoid a possible deadlock situation, processes that are children
134 are never sent SIGTTOU or SIGTTIN signals; rather, output or
136 are allowed and input attempts result in an end-of-file indication."
138 Currently (Linux 2.3.25),
142 and requires a kernel patch.
146 system call appeared in 3.0BSD.
147 .\" In the release notes for 4.2BSD Sam Leffler wrote: `vfork: Is still
148 .\" present, but definitely on its way out'.
149 In 4.4BSD it was made synonymous to
151 but NetBSD introduced it again,
152 cf. http://www.netbsd.org/Documentation/kernel/vfork.html .
153 In Linux, it has been equivalent to
155 until 2.2.0-pre6 or so. Since 2.2.0-pre9 (on i386, somewhat later on
156 other architectures) it is an independent system call. Support was
157 added in glibc 2.0.112.
159 4.3BSD, POSIX.1-2001.
161 The requirements put on
163 by the standards are weaker than those put on
165 so an implementation where the two are synonymous
166 is compliant. In particular, the programmer cannot
167 rely on the parent remaining blocked until a call of
171 and cannot rely on any specific behaviour w.r.t. shared memory.
172 .\" In AIXv3.1 vfork is equivalent to fork.