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 2012-08-05 "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)):
51 (_XOPEN_SOURCE\ >=\ 500 ||
52 _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED) &&
53 !(_POSIX_C_SOURCE\ >=\ 200809L || _XOPEN_SOURCE\ >=\ 700)
57 _BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500 ||
58 _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
63 .SS Standard description
67 function has the same effect as
69 except that the behavior is undefined if the process created by
71 either modifies any data other than a variable of type
73 used to store the return value from
75 or returns from the function in which
77 was called, or calls any other function before successfully calling
86 creates a child process of the calling process.
87 For details and return value and errors, see
93 It is used to create new processes without copying the page tables of
95 It may be useful in performance-sensitive applications
96 where a child is created which then immediately issues an
102 in that the calling thread is suspended until the child terminates
106 or abnormally, after delivery of a fatal signal),
107 or it makes a call to
109 Until that point, the child shares all memory with its parent,
111 The child must not return from the current function or call
118 the child process created by
120 inherits copies of various of the caller's process attributes
121 (e.g., file descriptors, signal dispositions, and current working directory);
124 call differs only in the treatment of the virtual address space,
127 Signals sent to the parent
128 arrive after the child releases the parent's memory
129 (i.e., after the child terminates
132 .SS Historic description
135 is implemented using copy-on-write pages, so the only penalty incurred by
137 is the time and memory required to duplicate the parent's page tables,
138 and to create a unique task structure for the child.
139 However, in the bad old days a
141 would require making a complete copy of the caller's data space,
142 often needlessly, since usually immediately afterward an
145 Thus, for greater efficiency, BSD introduced the
147 system call, which did not fully copy the address space of
148 the parent process, but borrowed the parent's memory and thread
149 of control until a call to
152 The parent process was suspended while the
153 child was using its resources.
156 was tricky: for example, not modifying data
157 in the parent process depended on knowing which variables were
160 4.3BSD; POSIX.1-2001 (but marked OBSOLETE).
161 POSIX.1-2008 removes the specification of
164 The requirements put on
166 by the standards are weaker than those put on
168 so an implementation where the two are synonymous is compliant.
169 In particular, the programmer cannot rely on the parent
170 remaining blocked until the child either terminates or calls
172 and cannot rely on any specific behavior with respect to shared memory.
173 .\" In AIXv3.1 vfork is equivalent to fork.
176 Some consider the semantics of
178 to be an architectural blemish, and the 4.2BSD man page stated:
179 "This system call will be eliminated when proper system sharing mechanisms
181 Users should not depend on the memory sharing semantics of
183 as it will, in that case, be made synonymous to
186 However, even though modern memory management hardware
187 has decreased the performance difference between
191 there are various reasons why Linux and other systems have retained
194 Some performance-critical applications require the small performance
195 advantage conferred by
199 can be implemented on systems that lack a memory-management unit (MMU), but
201 can't be implemented on such systems.
202 (POSIX.1-2008 removed
204 from the standard; the POSIX rationale for the
206 function notes that that function,
207 which provides functionality equivalent to
208 .BR fork (2)+ exec (3),
209 is designed to be implementable on systems that lack an MMU.)
210 .\" http://stackoverflow.com/questions/4259629/what-is-the-difference-between-fork-and-vfork
211 .\" http://developers.sun.com/solaris/articles/subprocess/subprocess.html
212 .\" http://mailman.uclinux.org/pipermail/uclinux-dev/2009-April/000684.html
214 Fork handlers established using
215 .BR pthread_atfork (3)
216 are not called when a multithreaded program employing
217 the NPTL threading library calls
219 Fork handlers are called in this case in a program using the
220 LinuxThreads threading library.
223 for a description of Linux threading libraries.)
227 is equivalent to calling
233 CLONE_VM | CLONE_VFORK | SIGCHLD
237 system call appeared in 3.0BSD.
238 .\" In the release notes for 4.2BSD Sam Leffler wrote: `vfork: Is still
239 .\" present, but definitely on its way out'.
240 In 4.4BSD it was made synonymous to
242 but NetBSD introduced it again,
244 .UR http://www.netbsd.org\:/Documentation\:/kernel\:/vfork.html
246 In Linux, it has been equivalent to
248 until 2.2.0-pre6 or so.
249 Since 2.2.0-pre9 (on i386, somewhat later on
250 other architectures) it is an independent system call.
251 Support was added in glibc 2.0.112.
254 Details of the signal handling are obscure and differ between systems.
255 The BSD man page states:
256 "To avoid a possible deadlock situation, processes that are children
263 signals; rather, output or
265 are allowed and input attempts result in an end-of-file indication."
267 .\" As far as I can tell, the following is not true in 2.6.19:
268 .\" Currently (Linux 2.3.25),
272 .\" and requires a kernel patch.
280 This page is part of release 3.68 of the Linux
283 A description of the project,
284 information about reporting bugs,
285 and the latest version of this page,
287 \%http://www.kernel.org/doc/man\-pages/.