1 .\" Copyright (c) 1999 Andries Brouwer (aeb@cwi.nl), 1 Nov 1999
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date. The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein. The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
25 .\" 1999-11-10: Merged text taken from the page contributed by
26 .\" Reed H. Petty (rhp@draper.net)
28 .TH VFORK 2 2016-03-15 "Linux" "Linux Programmer's Manual"
30 vfork \- create a child process and block parent
32 .B #include <sys/types.h>
34 .B #include <unistd.h>
39 Feature Test Macro Requirements for glibc (see
40 .BR feature_test_macros (7)):
50 (_XOPEN_SOURCE\ >=\ 500) && ! (_POSIX_C_SOURCE\ >=\ 200809L)
51 || /* Since glibc 2.19: */ _DEFAULT_SOURCE
52 || /* Glibc versions <= 2.19: */ _BSD_SOURCE
56 _BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500
57 .\" || _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
62 .SS Standard description
66 function has the same effect as
68 except that the behavior is undefined if the process created by
70 either modifies any data other than a variable of type
72 used to store the return value from
74 or returns from the function in which
76 was called, or calls any other function before successfully calling
85 creates a child process of the calling process.
86 For details and return value and errors, see
92 It is used to create new processes without copying the page tables of
94 It may be useful in performance-sensitive applications
95 where a child is created which then immediately issues an
101 in that the calling thread is suspended until the child terminates
105 or abnormally, after delivery of a fatal signal),
106 or it makes a call to
108 Until that point, the child shares all memory with its parent,
110 The child must not return from the current function or call
117 the child process created by
119 inherits copies of various of the caller's process attributes
120 (e.g., file descriptors, signal dispositions, and current working directory);
123 call differs only in the treatment of the virtual address space,
126 Signals sent to the parent
127 arrive after the child releases the parent's memory
128 (i.e., after the child terminates
131 .SS Historic description
134 is implemented using copy-on-write pages, so the only penalty incurred by
136 is the time and memory required to duplicate the parent's page tables,
137 and to create a unique task structure for the child.
138 However, in the bad old days a
140 would require making a complete copy of the caller's data space,
141 often needlessly, since usually immediately afterward an
144 Thus, for greater efficiency, BSD introduced the
146 system call, which did not fully copy the address space of
147 the parent process, but borrowed the parent's memory and thread
148 of control until a call to
151 The parent process was suspended while the
152 child was using its resources.
155 was tricky: for example, not modifying data
156 in the parent process depended on knowing which variables were
159 4.3BSD; POSIX.1-2001 (but marked OBSOLETE).
160 POSIX.1-2008 removes the specification of
163 The requirements put on
165 by the standards are weaker than those put on
167 so an implementation where the two are synonymous is compliant.
168 In particular, the programmer cannot rely on the parent
169 remaining blocked until the child either terminates or calls
171 and cannot rely on any specific behavior with respect to shared memory.
172 .\" In AIXv3.1 vfork is equivalent to fork.
175 Some consider the semantics of
177 to be an architectural blemish, and the 4.2BSD man page stated:
178 "This system call will be eliminated when proper system sharing mechanisms
180 Users should not depend on the memory sharing semantics of
182 as it will, in that case, be made synonymous to
185 However, even though modern memory management hardware
186 has decreased the performance difference between
190 there are various reasons why Linux and other systems have retained
193 Some performance-critical applications require the small performance
194 advantage conferred by
198 can be implemented on systems that lack a memory-management unit (MMU), but
200 can't be implemented on such systems.
201 (POSIX.1-2008 removed
203 from the standard; the POSIX rationale for the
205 function notes that that function,
206 which provides functionality equivalent to
207 .BR fork (2)+ exec (3),
208 is designed to be implementable on systems that lack an MMU.)
209 .\" http://stackoverflow.com/questions/4259629/what-is-the-difference-between-fork-and-vfork
210 .\" http://developers.sun.com/solaris/articles/subprocess/subprocess.html
211 .\" http://mailman.uclinux.org/pipermail/uclinux-dev/2009-April/000684.html
213 Fork handlers established using
214 .BR pthread_atfork (3)
215 are not called when a multithreaded program employing
216 the NPTL threading library calls
218 Fork handlers are called in this case in a program using the
219 LinuxThreads threading library.
222 for a description of Linux threading libraries.)
226 is equivalent to calling
232 CLONE_VM | CLONE_VFORK | SIGCHLD
236 system call appeared in 3.0BSD.
237 .\" In the release notes for 4.2BSD Sam Leffler wrote: `vfork: Is still
238 .\" present, but definitely on its way out'.
239 In 4.4BSD it was made synonymous to
241 but NetBSD introduced it again,
243 .UR http://www.netbsd.org\:/Documentation\:/kernel\:/vfork.html
245 In Linux, it has been equivalent to
247 until 2.2.0-pre6 or so.
248 Since 2.2.0-pre9 (on i386, somewhat later on
249 other architectures) it is an independent system call.
250 Support was added in glibc 2.0.112.
253 Details of the signal handling are obscure and differ between systems.
254 The BSD man page states:
255 "To avoid a possible deadlock situation, processes that are children
262 signals; rather, output or
264 are allowed and input attempts result in an end-of-file indication."
266 .\" As far as I can tell, the following is not true in 2.6.19:
267 .\" Currently (Linux 2.3.25),
271 .\" and requires a kernel patch.