Commit | Line | Data |
---|---|---|
2ced1824 BJ |
1 | .UC |
2 | .TH VFORK 2 | |
3 | .SH NAME | |
4 | vfork \- spawn new process in a virtual memory efficient way | |
5 | .SH SYNOPSIS | |
6 | \fBvfork()\fR | |
7 | .SH DESCRIPTION | |
8 | .I Vfork | |
9 | can be used to create new processes without fully copying the address | |
10 | space of the old process, which is horrendously inefficient in a paged | |
11 | environment. It is useful when the purpose of | |
12 | .I fork | |
13 | (2) would have been to create a new system context for an | |
14 | .I exec. | |
15 | .I Vfork | |
16 | differs from fork in that the parent's memory and thread of control run in | |
17 | the child's system context till a call to | |
18 | .I exec | |
19 | (2) or an exit | |
20 | (either by a call to | |
21 | .I exit | |
22 | (2) or abnormally.) | |
23 | The parent's process slot is suspended while it runs in the child's. | |
24 | .I Vfork | |
25 | returns 0 in the child's context and (later) the pid of the child in | |
26 | the parents context. | |
27 | .PP | |
28 | .I Vfork | |
29 | can normally be used just like | |
30 | .I fork. | |
31 | It does not work, however, to return while running in the childs context | |
32 | from the procedure which called | |
33 | .I vfork | |
34 | since the eventual return from | |
35 | .I vfork | |
36 | would then return to a no longer existant stack frame. | |
37 | Be careful, also, to call | |
38 | .I _exit | |
39 | rather than | |
40 | .I exit | |
41 | if you can't | |
42 | .I exec, | |
43 | since | |
44 | .I exit | |
45 | will flush and close standard I/O channels, and thereby mess up the | |
46 | parent processes standard I/O data structures. (Even with | |
47 | .I fork | |
48 | it is wrong to call | |
49 | .I exit | |
50 | since buffered data would then be flushed twice.) | |
51 | .SH SEE ALSO | |
52 | fork(2), exec(2), wait(2), | |
53 | .SH DIAGNOSTICS | |
54 | Same as for fork. | |
55 | .SH BUGS | |
56 | Would be unnecessary if | |
57 | .I fork | |
58 | were implemented by a mechanism similar to copy-on-write. | |
59 | The current system does not support this mechanism, however, necessitating | |
60 | .I vfork. |