Commit | Line | Data |
---|---|---|
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 |
20 | can be used to create new processes without fully copying the address |
21 | space of the old process, which is horrendously inefficient in a paged | |
22 | environment. It is useful when the purpose of | |
931b8415 | 23 | .Xr fork 2 |
d6ee9320 | 24 | would have been to create a new system context for an |
931b8415 CL |
25 | .Xr execve . |
26 | .Fn Vfork | |
d6ee9320 | 27 | differs from |
931b8415 | 28 | .Xr fork |
d6ee9320 KM |
29 | in that the child borrows the parent's memory and thread of |
30 | control until a call to | |
931b8415 | 31 | .Xr execve 2 |
d6ee9320 | 32 | or an exit (either by a call to |
931b8415 | 33 | .Xr exit 2 |
d6ee9320 KM |
34 | or abnormally.) |
35 | The parent process is suspended while the child is using its resources. | |
931b8415 CL |
36 | .Pp |
37 | .Fn Vfork | |
d6ee9320 KM |
38 | returns 0 in the child's context and (later) the pid of the child in |
39 | the parent's context. | |
931b8415 CL |
40 | .Pp |
41 | .Fn Vfork | |
d6ee9320 | 42 | can normally be used just like |
931b8415 | 43 | .Xr fork . |
d6ee9320 | 44 | It does not work, however, to return while running in the childs context |
eff6446c | 45 | from the procedure that called |
931b8415 | 46 | .Fn vfork |
d6ee9320 | 47 | since the eventual return from |
931b8415 | 48 | .Fn vfork |
d6ee9320 KM |
49 | would then return to a no longer existent stack frame. |
50 | Be careful, also, to call | |
931b8415 | 51 | .Xr _exit |
d6ee9320 | 52 | rather than |
931b8415 | 53 | .Xr exit |
d6ee9320 | 54 | if you can't |
931b8415 | 55 | .Xr execve , |
d6ee9320 | 56 | since |
931b8415 | 57 | .Xr exit |
d6ee9320 KM |
58 | will flush and close standard I/O channels, and thereby mess up the |
59 | parent processes standard I/O data structures. | |
60 | (Even with | |
931b8415 | 61 | .Xr fork |
d6ee9320 | 62 | it is wrong to call |
931b8415 | 63 | .Xr exit |
d6ee9320 | 64 | since 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 | 71 | Same as for |
931b8415 CL |
72 | .Xr fork . |
73 | .Sh BUGS | |
bf5bb190 KM |
74 | This system call will be eliminated when proper system sharing |
75 | mechanisms are implemented. | |
76 | Users should not depend on the memory | |
d6ee9320 | 77 | sharing semantics of |
931b8415 | 78 | .Xr vfork |
bf5bb190 | 79 | as it will, in that case, be made synonymous to |
931b8415 CL |
80 | .Xr fork . |
81 | .Pp | |
d6ee9320 | 82 | To avoid a possible deadlock situation, |
eff6446c | 83 | processes that are children in the middle |
d6ee9320 | 84 | of a |
931b8415 CL |
85 | .Fn vfork |
86 | are never sent | |
87 | .Dv SIGTTOU | |
88 | or | |
89 | .Dv SIGTTIN | |
90 | signals; rather, | |
d6ee9320 | 91 | output or |
931b8415 CL |
92 | .Xr ioctl 2 |
93 | calls | |
d6ee9320 KM |
94 | are allowed |
95 | and input attempts result in an end-of-file indication. | |
931b8415 CL |
96 | .Sh HISTORY |
97 | The | |
98 | .Nm | |
99 | function call appeared in | |
100 | .Bx 3.0 . |