Switch to SpeakEasy.net DSL

The Modular Manual Browser

Home Page
Manual: (HP-UX-11.11)
Apropos / Subsearch:
optional field

 vfork(2)							    vfork(2)

      vfork - spawn new process; share virtual memory

      #include <&lt&lt&lt;unistd.h>&gt&gt&gt;

      pid_t vfork(void);

      vfork() is a higher performance version of fork() that is provided on
      some systems where a performance advantage can be attained.

      If the calling process is multi-threaded, the newly created child
      process will only contain one thread. This one thread will be a copy
      of the thread calling vfork().

      vfork() differs from fork() only in that the child process can share
      code and data with the calling process (parent process).	This speeds
      cloning activity significantly at a risk to the integrity of the
      parent process if vfork() is misused.

      The use of vfork() for any purpose except as a prelude to an immediate
      exec() or exit() is not supported.  Any program that relies upon the
      differences between fork() and vfork() is not portable across HP-UX

      All HP-UX implementations must provide the entry vfork(), but it is
      permissible for them to treat it identically to fork.  On some
      implementations the two are not distinguished because the fork()
      implementation is as efficient as possible.  Other versions may do the
      same to avoid the overhead of supporting two similar calls.

      vfork() can be used to create new processes without fully copying the
      address space of the old process.	 If a forked process is simply going
      to do an exec() (see exec(2)), the data space copied from the parent
      to the child by fork() is not used.  This is particularly inefficient
      in a paged environment, making vfork is particularly useful.
      Depending upon the size of the parent's data space, vfork() can give a
      significant performance improvement over fork().

      vfork() differs from fork() in that the child borrows the parent's
      memory and thread of control until a call to exec() or an exit (either
      by a call to exit() or abnormally (see exec(2) and exit(2)).  The
      parent process is suspended while the child is using its resources.

      vfork() returns 0 in the child's context and (later) the pid of the
      child in the parent's context.

      vfork() can normally be used just like fork().  It does not work,
      however, to return while running in the child's context from the

 Hewlett-Packard Company	    - 1 -   HP-UX Release 11i: November 2000

 vfork(2)							    vfork(2)

      procedure which called vfork() since the eventual return from vfork()
      would then return to a no longer existent stack frame.  Be careful,
      also, to call _exit() rather than exit() if you cannot exec(), since
      exit() flushes and closes standard I/O channels, thereby damaging the
      parent process's standard I/O data structures.  (Even with fork() it
      is wrong to call exit() since buffered data would then be flushed

      The [vfork,exec] window begins at the vfork() call and ends when the
      child completes its exec() call.

      Upon successful completion, vfork() returns a value of 0 to the child
      process and returns the process ID of the child process to the parent
      process.	Otherwise, a value of -1 is returned to the parent, no child
      process is created, and errno is set to indicate the error.

      vfork() fails and no child process is created if any of the following
      conditions are encountered:

	   [EAGAIN]	  The system-wide limit on the total number of
			  processes under execution would be exceeded.

	   [EAGAIN]	  The system-imposed limit on the total number of
			  processes under execution by a single user would
			  be exceeded.

    Series 800
      Process times for the parent and child processes within the
      [vfork,exec] window may be inaccurate.

	   Parent and child processes share the same stack space within the
	   [vfork,exec] window.	 If the size of the stack has been changed
	   within this window by the child process (return from or call to a
	   function, for example), it is likely that the parent and child
	   processes will be killed with signal SIGSEGV or SIGBUS.

	   In the [vfork,exec] window, a call to signal() (see signal(2)
	   that installs a catching function can affect handling of the
	   signal by the parent.  The parent is not affected if the handling
	   is being set to SIG_DFL or SIG_IGN, or if either sigaction() or
	   sigvector() is used (see sigaction(2) and sigvector(2)).

      vfork() was developed by the University of California, Berkeley.

      exec(2), exit(2), fork(2), wait(2).

 Hewlett-Packard Company	    - 2 -   HP-UX Release 11i: November 2000