xref: /openbsd/lib/libc/sys/vfork.2 (revision 7b36286a)
1.\"	$OpenBSD: vfork.2,v 1.17 2008/04/24 20:43:20 kurt Exp $
2.\"	$NetBSD: vfork.2,v 1.8 1997/07/10 07:54:13 mikel Exp $
3.\"
4.\" Copyright (c) 1980, 1991, 1993
5.\"	The Regents of the University of California.  All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\" 1. Redistributions of source code must retain the above copyright
11.\"    notice, this list of conditions and the following disclaimer.
12.\" 2. Redistributions in binary form must reproduce the above copyright
13.\"    notice, this list of conditions and the following disclaimer in the
14.\"    documentation and/or other materials provided with the distribution.
15.\" 3. Neither the name of the University nor the names of its contributors
16.\"    may be used to endorse or promote products derived from this software
17.\"    without specific prior written permission.
18.\"
19.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29.\" SUCH DAMAGE.
30.\"
31.\"     @(#)vfork.2	8.1 (Berkeley) 6/4/93
32.\"
33.Dd $Mdocdate: April 24 2008 $
34.Dt VFORK 2
35.Os
36.Sh NAME
37.Nm vfork
38.Nd spawn new process and block parent
39.Sh SYNOPSIS
40.Fd #include <unistd.h>
41.Ft pid_t
42.Fn vfork void
43.Sh DESCRIPTION
44.Fn vfork
45was originally used to create new processes without fully copying the address
46space of the old process, which is horrendously inefficient in a paged
47environment.
48It was useful when the purpose of
49.Xr fork 2
50would have been to create a new system context for an
51.Xr execve 2 .
52Since
53.Xr fork 2
54is now efficient, even in the above case, the need for
55.Fn vfork
56has diminished.
57.Fn vfork
58differs from
59.Xr fork 2
60in that the parent is suspended until the child makes a call to
61.Xr execve 2
62or an exit (either by a call to
63.Xr _exit 2
64or abnormally).
65In addition, fork handlers established using
66.Xr pthread_atfork 3
67are not called when a multithreaded program calls
68.Fn vfork .
69.Pp
70.Fn vfork
71returns 0 in the child's context and (later) the PID of the child in
72the parent's context.
73.Sh RETURN VALUES
74Same as for
75.Xr fork 2 .
76.Sh SEE ALSO
77.Xr execve 2 ,
78.Xr fork 2 ,
79.Xr sigaction 2 ,
80.Xr wait 2
81.Sh HISTORY
82The
83.Fn vfork
84function call appeared in
85.Bx 2.9 .
86.Sh BUGS
87To avoid a possible deadlock situation, processes that are children
88in the middle of a
89.Fn vfork
90are never sent
91.Dv SIGTTOU
92or
93.Dv SIGTTIN
94signals; rather, output or
95.Xr ioctl 2
96calls are allowed and input attempts result in an end-of-file indication.
97