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