.\" Copyright (c) 1999 Andries Brouwer (aeb@cwi.nl), 1 Nov 1999
.\"
+.\" %%%LICENSE_START(VERBATIM)
.\" Permission is granted to make and distribute verbatim copies of this
.\" manual provided the copyright notice and this permission notice are
.\" preserved on all copies.
.\"
.\" Formatted or processed versions of this manual, if unaccompanied by
.\" the source, must acknowledge the copyright and authors of this work.
+.\" %%%LICENSE_END
.\"
.\" 1999-11-10: Merged text taken from the page contributed by
.\" Reed H. Petty (rhp@draper.net)
.\"
-.TH VFORK 2 2009-06-21 "Linux" "Linux Programmer's Manual"
+.TH VFORK 2 2012-08-05 "Linux" "Linux Programmer's Manual"
.SH NAME
vfork \- create a child process and block parent
.SH SYNOPSIS
.in
.sp
.BR vfork ():
-_BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500
+.ad l
+.RS 4
+.PD 0
+.TP 4
+Since glibc 2.12:
+.nf
+_BSD_SOURCE ||
+ (_XOPEN_SOURCE\ >=\ 500 ||
+ _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED) &&
+ !(_POSIX_C_SOURCE\ >=\ 200809L || _XOPEN_SOURCE\ >=\ 700)
+.TP 4
+.fi
+Before glibc 2.12:
+_BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500 ||
+_XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
+.PD
+.RE
+.ad b
.SH DESCRIPTION
-.SS "Standard Description"
+.SS Standard description
(From POSIX.1)
The
.BR vfork ()
or one of the
.BR exec (3)
family of functions.
-.SS "Linux Description"
+.SS Linux description
.BR vfork (),
just like
.BR fork (2),
It is used to create new processes without copying the page tables of
the parent process.
It may be useful in performance-sensitive applications
-where a child will be created which then immediately issues an
+where a child is created which then immediately issues an
.BR execve (2).
.PP
.BR vfork ()
differs from
.BR fork (2)
-in that the parent is suspended until the child terminates
+in that the calling thread is suspended until the child terminates
(either normally,
by calling
.BR _exit (2),
.BR exit (3),
but may call
.BR _exit (2).
-.PP
-Signal handlers are inherited, but not shared.
-Signals to the parent
+
+As with
+.BR fork (2),
+the child process created by
+.BR vfork ()
+inherits copies of various of the caller's process attributes
+(e.g., file descriptors, signal dispositions, and current working directory);
+the
+.BR vfork ()
+call differs only in the treatment of the virtual address space,
+as described above.
+
+Signals sent to the parent
arrive after the child releases the parent's memory
(i.e., after the child terminates
or calls
.BR execve (2)).
-.SS "Historic Description"
+.SS Historic description
Under Linux,
.BR fork (2)
is implemented using copy-on-write pages, so the only penalty incurred by
However, in the bad old days a
.BR fork (2)
would require making a complete copy of the caller's data space,
-often needlessly, since usually immediately afterwards an
+often needlessly, since usually immediately afterward an
.BR exec (3)
is done.
Thus, for greater efficiency, BSD introduced the
The use of
.BR vfork ()
was tricky: for example, not modifying data
-in the parent process depended on knowing which variables are
+in the parent process depended on knowing which variables were
held in a register.
-.SH "CONFORMING TO"
-4.3BSD, POSIX.1-2001.
+.SH CONFORMING TO
+4.3BSD; POSIX.1-2001 (but marked OBSOLETE).
POSIX.1-2008 removes the specification of
.BR vfork ().
+
The requirements put on
.BR vfork ()
by the standards are weaker than those put on
and cannot rely on any specific behavior with respect to shared memory.
.\" In AIXv3.1 vfork is equivalent to fork.
.SH NOTES
-.SS Linux Notes
+.PP
+Some consider the semantics of
+.BR vfork ()
+to be an architectural blemish, and the 4.2BSD man page stated:
+"This system call will be eliminated when proper system sharing mechanisms
+are implemented.
+Users should not depend on the memory sharing semantics of
+.BR vfork ()
+as it will, in that case, be made synonymous to
+.BR fork (2).\c
+"
+However, even though modern memory management hardware
+has decreased the performance difference between
+.BR fork (2)
+and
+.BR vfork (),
+there are various reasons why Linux and other systems have retained
+.BR vfork ():
+.IP * 3
+Some performance-critical applications require the small performance
+advantage conferred by
+.BR vfork ().
+.IP *
+.BR vfork ()
+can be implemented on systems that lack a memory-management unit (MMU), but
+.BR fork (2)
+can't be implemented on such systems.
+(POSIX.1-2008 removed
+.BR vfork ()
+from the standard; the POSIX rationale for the
+.BR posix_spawn (3)
+function notes that that function,
+which provides functionality equivalent to
+.BR fork (2)+ exec (3),
+is designed to be implementable on systems that lack an MMU.)
+.\" http://stackoverflow.com/questions/4259629/what-is-the-difference-between-fork-and-vfork
+.\" http://developers.sun.com/solaris/articles/subprocess/subprocess.html
+.\" http://mailman.uclinux.org/pipermail/uclinux-dev/2009-April/000684.html
+.SS Linux notes
Fork handlers established using
.BR pthread_atfork (3)
are not called when a multithreaded program employing
(See
.BR pthreads (7)
for a description of Linux threading libraries.)
+
+A call to
+.BR vfork ()
+is equivalent to calling
+.BR clone (2)
+with
+.I flags
+specified as:
+
+ CLONE_VM | CLONE_VFORK | SIGCHLD
.SS History
The
.BR vfork ()
In 4.4BSD it was made synonymous to
.BR fork (2)
but NetBSD introduced it again,
-cf. http://www.netbsd.org/Documentation/kernel/vfork.html .
+cf.
+.UR http://www.netbsd.org\:/Documentation\:/kernel\:/vfork.html
+.UE .
In Linux, it has been equivalent to
.BR fork (2)
until 2.2.0-pre6 or so.
other architectures) it is an independent system call.
Support was added in glibc 2.0.112.
.SH BUGS
-It is rather unfortunate that Linux revived this specter from the past.
-The BSD man page states:
-"This system call will be eliminated when proper system sharing mechanisms
-are implemented.
-Users should not depend on the memory sharing semantics of
-.BR vfork ()
-as it will, in that case, be made synonymous to
-.BR fork (2).\c
-"
-
+.PP
Details of the signal handling are obscure and differ between systems.
The BSD man page states:
"To avoid a possible deadlock situation, processes that are children
.\" cannot follow
.\" .BR vfork ()
.\" and requires a kernel patch.
-.SH "SEE ALSO"
+.SH SEE ALSO
.BR clone (2),
.BR execve (2),
.BR fork (2),
.BR unshare (2),
.BR wait (2)
+.SH COLOPHON
+This page is part of release 3.68 of the Linux
+.I man-pages
+project.
+A description of the project,
+information about reporting bugs,
+and the latest version of this page,
+can be found at
+\%http://www.kernel.org/doc/man\-pages/.