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 2007-07-26 "Linux" "Linux Programmer's Manual"
28 vfork \- create a child process and block parent
30 .B #include <sys/types.h>
32 .B #include <unistd.h>
37 Feature Test Macro Requirements for glibc (see
38 .BR feature_test_macros (7)):
42 _BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500
44 .SS "Standard Description"
45 (From SUSv2 / POSIX draft.)
48 function has the same effect as
50 except that the behavior is undefined if the process created by
52 either modifies any data other than a variable of type
54 used to store the return value from
56 or returns from the function in which
58 was called, or calls any other function before successfully calling
63 .SS "Linux Description"
67 creates a child process of the calling process.
68 For details and return value and errors, see
74 It is used to create new processes without copying the page tables of
76 It may be useful in performance sensitive applications
77 where a child will be created which then immediately issues an
83 in that the parent is suspended until the child makes a call to
87 The child shares all memory with its parent, including the stack, until
89 is issued by the child.
90 The child must not return from the current function or call
95 Signal handlers are inherited, but not shared.
97 arrive after the child releases the parent's memory.
98 .SS "Historic Description"
101 is implemented using copy-on-write pages, so the only penalty incurred by
103 is the time and memory required to duplicate the parent's page tables,
104 and to create a unique task structure for the child.
105 However, in the bad old days a
107 would require making a complete copy of the caller's data space,
108 often needlessly, since usually immediately afterwards an
111 Thus, for greater efficiency, BSD introduced the
113 system call, that did not fully copy the address space of
114 the parent process, but borrowed the parent's memory and thread
115 of control until a call to
118 The parent process was suspended while the
119 child was using its resources.
122 was tricky: for example, not modifying data
123 in the parent process depended on knowing which variables are
126 4.3BSD, POSIX.1-2001.
127 .\" FIXME . Mar 07: in the draft of the next POSIX revision, the spec for
128 .\" vfork() has been removed. See if this remains so in final version.
129 The requirements put on
131 by the standards are weaker than those put on
133 so an implementation where the two are synonymous is compliant.
134 In particular, the programmer cannot
135 rely on the parent remaining blocked until a call of
139 and cannot rely on any specific behavior wth respect to shared memory.
140 .\" In AIXv3.1 vfork is equivalent to fork.
143 Fork handlers established using
144 .BR pthread_atfork (3)
145 are not called when a multithreaded program employing
146 the NPTL threading library calls
148 Fork handlers are called in this case in a program using the
149 LinuxThreads threading library.
152 for a description of Linux threading libraries.)
156 system call appeared in 3.0BSD.
157 .\" In the release notes for 4.2BSD Sam Leffler wrote: `vfork: Is still
158 .\" present, but definitely on its way out'.
159 In 4.4BSD it was made synonymous to
161 but NetBSD introduced it again,
162 cf. http://www.netbsd.org/Documentation/kernel/vfork.html .
163 In Linux, it has been equivalent to
165 until 2.2.0-pre6 or so.
166 Since 2.2.0-pre9 (on i386, somewhat later on
167 other architectures) it is an independent system call.
168 Support was added in glibc 2.0.112.
170 It is rather unfortunate that Linux revived this specter from the past.
171 The BSD man page states:
172 "This system call will be eliminated when proper system sharing mechanisms
174 Users should not depend on the memory sharing semantics of
176 as it will, in that case, be made synonymous to
180 Details of the signal handling are obscure and differ between systems.
181 The BSD man page states:
182 "To avoid a possible deadlock situation, processes that are children
189 signals; rather, output or
191 are allowed and input attempts result in an end-of-file indication."
193 .\" As far as I can tell, the following is not true in 2.6.19:
194 .\" Currently (Linux 2.3.25),
198 .\" and requires a kernel patch.