Commit | Line | Data |
---|---|---|
d6ee9320 KM |
1 | .\" Copyright (c) 1980 Regents of the University of California. |
2 | .\" All rights reserved. The Berkeley software License Agreement | |
3 | .\" specifies the terms and conditions for redistribution. | |
4 | .\" | |
eff6446c | 5 | .\" @(#)vfork.2 6.2 (Berkeley) %G% |
d6ee9320 | 6 | .\" |
71fb3f26 | 7 | .TH VFORK 2 "" |
d6ee9320 KM |
8 | .UC 4 |
9 | .SH NAME | |
10 | vfork \- spawn new process in a virtual memory efficient way | |
11 | .SH SYNOPSIS | |
bf5bb190 KM |
12 | .B pid = vfork() |
13 | .br | |
14 | .B int pid; | |
d6ee9320 KM |
15 | .SH DESCRIPTION |
16 | .I Vfork | |
17 | can be used to create new processes without fully copying the address | |
18 | space of the old process, which is horrendously inefficient in a paged | |
19 | environment. It is useful when the purpose of | |
20 | .IR fork (2) | |
21 | would have been to create a new system context for an | |
bf5bb190 | 22 | .IR execve . |
d6ee9320 KM |
23 | .I Vfork |
24 | differs from | |
25 | .I fork | |
26 | in that the child borrows the parent's memory and thread of | |
27 | control until a call to | |
bf5bb190 | 28 | .IR execve (2) |
d6ee9320 KM |
29 | or an exit (either by a call to |
30 | .IR exit (2) | |
31 | or abnormally.) | |
32 | The parent process is suspended while the child is using its resources. | |
33 | .PP | |
34 | .I Vfork | |
35 | returns 0 in the child's context and (later) the pid of the child in | |
36 | the parent's context. | |
37 | .PP | |
38 | .I Vfork | |
39 | can normally be used just like | |
40 | .I fork. | |
41 | It does not work, however, to return while running in the childs context | |
eff6446c | 42 | from the procedure that called |
d6ee9320 KM |
43 | .I vfork |
44 | since the eventual return from | |
45 | .I vfork | |
46 | would then return to a no longer existent stack frame. | |
47 | Be careful, also, to call | |
48 | .I _exit | |
49 | rather than | |
50 | .I exit | |
51 | if you can't | |
bf5bb190 | 52 | .IR execve , |
d6ee9320 KM |
53 | since |
54 | .I exit | |
55 | will flush and close standard I/O channels, and thereby mess up the | |
56 | parent processes standard I/O data structures. | |
57 | (Even with | |
58 | .I fork | |
59 | it is wrong to call | |
60 | .I exit | |
61 | since buffered data would then be flushed twice.) | |
d6ee9320 | 62 | .SH SEE ALSO |
bf5bb190 | 63 | fork(2), execve(2), sigvec(2), wait(2), |
d6ee9320 KM |
64 | .SH DIAGNOSTICS |
65 | Same as for | |
66 | .IR fork . | |
67 | .SH BUGS | |
bf5bb190 KM |
68 | This system call will be eliminated when proper system sharing |
69 | mechanisms are implemented. | |
70 | Users should not depend on the memory | |
d6ee9320 KM |
71 | sharing semantics of |
72 | .I vfork | |
bf5bb190 KM |
73 | as it will, in that case, be made synonymous to |
74 | .IR fork . | |
d6ee9320 KM |
75 | .PP |
76 | To avoid a possible deadlock situation, | |
eff6446c | 77 | processes that are children in the middle |
d6ee9320 KM |
78 | of a |
79 | .I vfork | |
80 | are never sent SIGTTOU or SIGTTIN signals; rather, | |
81 | output or | |
82 | .IR ioctl s | |
83 | are allowed | |
84 | and input attempts result in an end-of-file indication. |