1VFORK(P) POSIX Programmer's Manual VFORK(P)
2
3
4
6 vfork - create a new process; share virtual memory
7
9 #include <unistd.h>
10
11 pid_t vfork(void);
12
13
15 The vfork() function shall be equivalent to fork(), except that the
16 behavior is undefined if the process created by vfork() either modifies
17 any data other than a variable of type pid_t used to store the return
18 value from vfork(), or returns from the function in which vfork() was
19 called, or calls any other function before successfully calling _exit()
20 or one of the exec family of functions.
21
23 Upon successful completion, vfork() shall return 0 to the child process
24 and return the process ID of the child process to the parent process.
25 Otherwise, -1 shall be returned to the parent, no child process shall
26 be created, and errno shall be set to indicate the error.
27
29 The vfork() function shall fail if:
30
31 EAGAIN The system-wide limit on the total number of processes under
32 execution would be exceeded, or the system-imposed limit on the
33 total number of processes under execution by a single user would
34 be exceeded.
35
36 ENOMEM There is insufficient swap space for the new process.
37
38
39 The following sections are informative.
40
42 None.
43
45 Conforming applications are recommended not to depend on vfork(), but
46 to use fork() instead. The vfork() function may be withdrawn in a
47 future version.
48
49 On some implementations, vfork() is equivalent to fork().
50
51 The vfork() function differs from fork() only in that the child process
52 can share code and data with the calling process (parent process). This
53 speeds cloning activity significantly at a risk to the integrity of the
54 parent process if vfork() is misused.
55
56 The use of vfork() for any purpose except as a prelude to an immediate
57 call to a function from the exec family, or to _exit(), is not advised.
58
59 The vfork() function can be used to create new processes without fully
60 copying the address space of the old process. If a forked process is
61 simply going to call exec, the data space copied from the parent to the
62 child by fork() is not used. This is particularly inefficient in a
63 paged environment, making vfork() particularly useful. Depending upon
64 the size of the parent's data space, vfork() can give a significant
65 performance improvement over fork().
66
67 The vfork() function can normally be used just like fork(). It does
68 not work, however, to return while running in the child's context from
69 the caller of vfork() since the eventual return from vfork() would then
70 return to a no longer existent stack frame. Care should be taken,
71 also, to call _exit() rather than exit() if exec cannot be used, since
72 exit() flushes and closes standard I/O channels, thereby damaging the
73 parent process' standard I/O data structures. (Even with fork(), it is
74 wrong to call exit(), since buffered data would then be flushed twice.)
75
76 If signal handlers are invoked in the child process after vfork(), they
77 must follow the same rules as other code in the child process.
78
80 None.
81
83 This function may be withdrawn in a future version.
84
86 exec() , exit() , fork() , wait() , the Base Definitions volume of
87 IEEE Std 1003.1-2001, <unistd.h>
88
90 Portions of this text are reprinted and reproduced in electronic form
91 from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
92 -- Portable Operating System Interface (POSIX), The Open Group Base
93 Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
94 Electrical and Electronics Engineers, Inc and The Open Group. In the
95 event of any discrepancy between this version and the original IEEE and
96 The Open Group Standard, the original IEEE and The Open Group Standard
97 is the referee document. The original Standard can be obtained online
98 at http://www.opengroup.org/unix/online.html .
99
100
101
102IEEE/The Open Group 2003 VFORK(P)