1VFORK(2)                   Linux Programmer's Manual                  VFORK(2)
2
3
4

NAME

6       vfork - create a child process and block parent
7

SYNOPSIS

9       #include <sys/types.h>
10       #include <unistd.h>
11
12       pid_t vfork(void);
13
14   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
15
16       vfork():
17           Since glibc 2.12:
18               (_XOPEN_SOURCE >= 500) && ! (_POSIX_C_SOURCE >= 200809L)
19                   || /* Since glibc 2.19: */ _DEFAULT_SOURCE
20                   || /* Glibc versions <= 2.19: */ _BSD_SOURCE
21           Before glibc 2.12:
22               _BSD_SOURCE || _XOPEN_SOURCE >= 500
23

DESCRIPTION

25   Standard description
26       (From  POSIX.1)  The  vfork()  function has the same effect as fork(2),
27       except that the behavior is undefined if the process created by vfork()
28       either  modifies  any  data other than a variable of type pid_t used to
29       store the return value from vfork(), or returns from  the  function  in
30       which  vfork()  was called, or calls any other function before success‐
31       fully calling _exit(2) or one of the exec(3) family of functions.
32
33   Linux description
34       vfork(), just like fork(2), creates a  child  process  of  the  calling
35       process.  For details and return value and errors, see fork(2).
36
37       vfork()  is  a special case of clone(2).  It is used to create new pro‐
38       cesses without copying the page tables of the parent process.   It  may
39       be  useful  in performance-sensitive applications where a child is cre‐
40       ated which then immediately issues an execve(2).
41
42       vfork() differs from fork(2) in that the calling  thread  is  suspended
43       until  the  child  terminates (either normally, by calling _exit(2), or
44       abnormally, after delivery of a fatal signal), or it makes  a  call  to
45       execve(2).  Until that point, the child shares all memory with its par‐
46       ent, including the stack.  The child must not return from  the  current
47       function  or  call exit(3) (which would have the effect of calling exit
48       handlers established by the parent process and  flushing  the  parent's
49       stdio(3) buffers), but may call _exit(2).
50
51       As  with  fork(2), the child process created by vfork() inherits copies
52       of various of the caller's process attributes (e.g., file  descriptors,
53       signal  dispositions,  and current working directory); the vfork() call
54       differs only  in  the  treatment  of  the  virtual  address  space,  as
55       described above.
56
57       Signals sent to the parent arrive after the child releases the parent's
58       memory (i.e., after the child terminates or calls execve(2)).
59
60   Historic description
61       Under Linux, fork(2) is implemented using copy-on-write pages,  so  the
62       only  penalty  incurred  by  fork(2) is the time and memory required to
63       duplicate the parent's page tables, and to create a unique task  struc‐
64       ture  for  the  child.   However