flag fields are u_int's
[unix-history] / usr / src / lib / libc / sys / vfork.2
CommitLineData
931b8415
CL
1.\" Copyright (c) 1980, 1991 Regents of the University of California.
2.\" All rights reserved.
d6ee9320 3.\"
931b8415 4.\" %sccs.include.redist.man%
d6ee9320 5.\"
931b8415
CL
6.\" @(#)vfork.2 6.3 (Berkeley) %G%
7.\"
8.Dd
9.Dt VFORK 2
10.Os BSD 4
11.Sh NAME
12.Nm vfork
13.Nd spawn new process in a virtual memory efficient way
14.Sh SYNOPSIS
15.Fd #include <unistd.h>
16.Ft int
17.Fn vfork void
18.Sh DESCRIPTION
19.Fn Vfork
d6ee9320
KM
20can be used to create new processes without fully copying the address
21space of the old process, which is horrendously inefficient in a paged
22environment. It is useful when the purpose of
931b8415 23.Xr fork 2
d6ee9320 24would have been to create a new system context for an
931b8415
CL
25.Xr execve .
26.Fn Vfork
d6ee9320 27differs from
931b8415 28.Xr fork
d6ee9320
KM
29in that the child borrows the parent's memory and thread of
30control until a call to
931b8415 31.Xr execve 2
d6ee9320 32or an exit (either by a call to
931b8415 33.Xr exit 2
d6ee9320
KM
34or abnormally.)
35The parent process is suspended while the child is using its resources.
931b8415
CL
36.Pp
37.Fn Vfork
d6ee9320
KM
38returns 0 in the child's context and (later) the pid of the child in
39the parent's context.
931b8415
CL
40.Pp
41.Fn Vfork
d6ee9320 42can normally be used just like
931b8415 43.Xr fork .
d6ee9320 44It does not work, however, to return while running in the childs context
eff6446c 45from the procedure that called
931b8415 46.Fn vfork
d6ee9320 47since the eventual return from
931b8415 48.Fn vfork
d6ee9320
KM
49would then return to a no longer existent stack frame.
50Be careful, also, to call
931b8415 51.Xr _exit
d6ee9320 52rather than
931b8415 53.Xr exit
d6ee9320 54if you can't
931b8415 55.Xr execve ,
d6ee9320 56since
931b8415 57.Xr exit
d6ee9320
KM
58will flush and close standard I/O channels, and thereby mess up the
59parent processes standard I/O data structures.
60(Even with
931b8415 61.Xr fork
d6ee9320 62it is wrong to call
931b8415 63.Xr exit
d6ee9320 64since buffered data would then be flushed twice.)
931b8415
CL
65.Sh SEE ALSO
66.Xr fork 2 ,
67.Xr execve 2 ,
68.Xr sigvec 2 ,
69.Xr wait 2 ,
70.Sh DIAGNOSTICS
d6ee9320 71Same as for
931b8415
CL
72.Xr fork .
73.Sh BUGS
bf5bb190
KM
74This system call will be eliminated when proper system sharing
75mechanisms are implemented.
76Users should not depend on the memory
d6ee9320 77sharing semantics of
931b8415 78.Xr vfork
bf5bb190 79as it will, in that case, be made synonymous to
931b8415
CL
80.Xr fork .
81.Pp
d6ee9320 82To avoid a possible deadlock situation,
eff6446c 83processes that are children in the middle
d6ee9320 84of a
931b8415
CL
85.Fn vfork
86are never sent
87.Dv SIGTTOU
88or
89.Dv SIGTTIN
90signals; rather,
d6ee9320 91output or
931b8415
CL
92.Xr ioctl 2
93calls
d6ee9320
KM
94are allowed
95and input attempts result in an end-of-file indication.
931b8415
CL
96.Sh HISTORY
97The
98.Nm
99function call appeared in
100.Bx 3.0 .