1 VFORK(2)                         System Calls                         VFORK(2)
   2 
   3 NAME
   4      vfork, vforkx  spawn new process in a virtual memory efficient way
   5 
   6 SYNOPSIS
   7      #include <unistd.h>
   8 
   9      pid_t
  10      vfork(void);
  11 
  12      #include <sys/fork.h>
  13 
  14      pid_t
  15      vforkx(int flags);
  16 
  17 DESCRIPTION
  18      The vfork() and vforkx() functions create a new process without fully
  19      copying the address space of the old process. These functions are useful
  20      in instances where the purpose of a fork(2) operation is to create a new
  21      system context for an exec(2) operation.
  22 
  23      Unlike with the fork() function, the child process borrows the parent's
  24      memory and thread of control until a call to execve() or an exit (either
  25      abnormally or by a call to _exit(2)).  Any modification made during this
  26      time to any part of memory in the child process is reflected in the
  27      parent process on return from vfork() or vforkx().  The parent process is
  28      suspended while the child is using its resources.
  29 
  30      In a multithreaded application, vfork() and vforkx() borrow only the
  31      thread of control that called vfork() or vforkx() in the parent; that is,
  32      the child contains only one thread. The use of vfork() or vforkx() in
  33      multithreaded applications, however, is unsafe due to race conditions
  34      that can cause the child process to become deadlocked and consequently
  35      block both the child and parent process from execution indefinitely.
  36 
  37      The vfork() and vforkx() functions can normally be used the same way as
  38      fork() and forkx(), respectively. The calling procedure, however, should
  39      not return while running in the child's context, since the eventual
  40      return from vfork() or vforkx() in the parent would be to a stack frame
  41      that no longer exists. The _exit() function should be used in favor of
  42      exit(3C) if unable to perform an execve() operation, since exit() will
  43      invoke all functions registered by atexit(3C) and will flush and close
  44      standard I/O channels, thereby corrupting the parent process's standard
  45      I/O data structures. Care must be taken in the child process not to
  46      modify any global or local data that affects the behavior of the parent
  47      process on return from vfork() or vforkx(), unless such an effect is
  48      intentional.
  49 
  50      Unlike fork() and forkx(), fork handlers are not run when vfork() and
  51      vforkx() are called.
  52 
  53      The vfork() and vforkx() functions are deprecated. Their sole legitimate
  54      use as a prelude to an immediate call to a function from the exec(2)
  55      family can be achieved safely by posix_spawn(3C) or posix_spawnp(3C).
  56 
  57    Fork Extensions
  58      The vforkx() function accepts a flags argument consisting of a bitwise
  59      inclusive-OR of zero or more of the following flags, which are defined in
  60      the header <sys/fork.h>:
  61 
  62            FORK_NOSIGCHLD
  63            FORK_WAITPID
  64 
  65      See fork(2) for descriptions of these flags. If the flags argument is 0,
  66      vforkx() is identical to vfork().
  67 
  68 RETURN VALUES
  69      Upon successful completion, vfork() and vforkx() return 0 to the child
  70      process and return the process ID of the child process to the parent
  71      process. Otherwise, 1 is returned to the parent process, no child process
  72      is created, and errno is set to indicate the error.
  73 
  74 ERRORS
  75      The vfork() and vforkx() functions will fail if:
  76 
  77      EAGAIN             The system-imposed limit on the total number of
  78                         processes under execution (either system-quality or by
  79                         a single user) would be exceeded. This limit is
  80                         determined when the system is generated.
  81 
  82      ENOMEM             There is insufficient swap space for the new process.
  83 
  84      The vforkx() function will fail if:
  85 
  86      EINVAL             The flags argument is invalid.
  87 
  88 INTERFACE STABILITY
  89      The vfork() function is Obsolete Standard.
  90 
  91      The vforkx() function is Obsolete Uncommitted.
  92 
  93 MT-LEVEL
  94      Unsafe.
  95 
  96 SEE ALSO
  97      exec(2), exit(2), fork(2), ioctl(2), atexit(3C), exit(3C),
  98      posix_spawn(3C), posix_spawnp(3C), signal.h(3HEAD), wait(3C),
  99      standards(5)
 100 
 101 NOTES
 102      To avoid a possible deadlock situation, processes that are children in
 103      the middle of a vfork() or vforkx() are never sent SIGTTOU or SIGTTIN
 104      signals; rather, output or ioctls are allowed and input attempts result
 105      in an EOF indication.
 106 
 107      To forestall parent memory corruption due to race conditions with signal
 108      handling, vfork() and vforkx() treat signal handlers in the child process
 109      in the same manner as the exec(2) functions: signals set to be caught by
 110      the parent process are set to the default action (SIG_DFL) in the child
 111      process (see signal.h(3HEAD)).  Any attempt to set a signal handler in
 112      the child before execve() to anything other than SIG_DFL or SIG_IGN is
 113      disallowed and results in setting the handler to SIG_DFL.
 114 
 115      On some systems, the implementation of vfork() and vforkx() cause the
 116      parent to inherit register values from the child. This can create
 117      problems for certain optimizing compilers if <unistd.h> is   not included
 118      in the source calling vfork() or if <sys/fork.h> is not included in the
 119      source calling vforkx().
 120 
 121 STANDARDS
 122      The vfork() function is available in the following compilation
 123      environments.  See standards(5).
 124 
 125         X/Open Portability Guide Issue4, Version2 (XPG4.2)
 126         Version2 of the Single UNIX Specification (SUSv2)
 127         Version3 of the Single UNIX Specification (SUSv3)
 128 
 129      It was marked obsolete in Version3 of the Single UNIX Specification
 130      (SUSv3) and removed from IEEE Std 1003.1-2008 (POSIX.1).
 131 
 132      The vforkx() function is a local extension and not available in any
 133      strictly standards-compliant compilation environment.
 134 
 135 illumos                         August 20, 2014                        illumos