| 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 | .\" |
| 5 | .\" @(#)vfork.2 6.2 (Berkeley) %G% |
| 6 | .\" |
| 7 | .TH VFORK 2 "" |
| 8 | .UC 4 |
| 9 | .SH NAME |
| 10 | vfork \- spawn new process in a virtual memory efficient way |
| 11 | .SH SYNOPSIS |
| 12 | .B pid = vfork() |
| 13 | .br |
| 14 | .B int pid; |
| 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 |
| 22 | .IR execve . |
| 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 |
| 28 | .IR execve (2) |
| 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 |
| 42 | from the procedure that called |
| 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 |
| 52 | .IR execve , |
| 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.) |
| 62 | .SH SEE ALSO |
| 63 | fork(2), execve(2), sigvec(2), wait(2), |
| 64 | .SH DIAGNOSTICS |
| 65 | Same as for |
| 66 | .IR fork . |
| 67 | .SH BUGS |
| 68 | This system call will be eliminated when proper system sharing |
| 69 | mechanisms are implemented. |
| 70 | Users should not depend on the memory |
| 71 | sharing semantics of |
| 72 | .I vfork |
| 73 | as it will, in that case, be made synonymous to |
| 74 | .IR fork . |
| 75 | .PP |
| 76 | To avoid a possible deadlock situation, |
| 77 | processes that are children in the middle |
| 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. |