vfork man page on BSDi

Man page or keyword search:  
man Server   6284 pages
apropos Keyword Search (all sections)
Output format
BSDi logo
[printable version]

VFORK(2)		    BSD Programmer's Manual		      VFORK(2)

NAME
     vfork - create a new process in a virtual memory efficient way

SYNOPSIS
     #include <unistd.h>

     int
     vfork(void);

DESCRIPTION
     Vfork() creates a new process that shares the virtual memory of the cur-
     rent process.  Vfork() can be a more efficient replacement for fork(2)
     when the purpose of fork(2) would have been to create a new system con-
     text for an execve(2).  The parent process is suspended until the child
     makes a successful call to execve(2) or exits (either by calling _exit(2)
     or by receiving a fatal signal).

     These rules of programming must be followed in order to use vfork() safe-
     ly:

     o	 The function that calls vfork() must not return in the child process.
	 The child process must call execve(2) or exit without returning.
	 Failure to observe this rule can result in very mysterious core dumps
	 or stack corruption in the parent process.

     o	 The child process should call _exit(2) rather than exit(3) to exit
	 explicitly.  The exit(3) function flushes buffered I/O, executes C++
	 destructor functions and calls functions that have been registered
	 using atexit(3).  Since the child process shares memory with the par-
	 ent process, these actions may inappropriately change the state of
	 the parent process.

     o	 Be very careful about any action in the child that might change the
	 state of the parent in unexpected ways.  For example, a call to
	 setenv(3) in the child process after a call to vfork() may change the
	 environment list in both the parent and the child.

     A call to vfork() is exactly the same as a call to sfork(2),  with param-
     eters as follows:

	   sfork(SF_MEM|SF_WAITCHILD, NULL, SIGCHLD)

SEE ALSO
     fork(2),  execve(2),  sfork(2),  sigaction(2),  wait(2).

ERRORS
     Vfork() will fail and no child process will be created if:

     [EAGAIN]  The system-imposed limit on the total number of processes under
	       execution would be exceeded.  This limit is configuration-de-
	       pendent.

     [EAGAIN]  The system-imposed RLIMIT_NPROC resource limit on the total
	       number of processes under execution by the invoking user would
	       be exceeded.  See setrlimit(2).

     [ENOMEM]  There is insufficient swap space for the new process.

BUGS
     Vfork() is extremely easy to misuse.   Unless your program really needs
     the efficiency advantage of vfork(), you should use fork(2) instead.

     To avoid a possible deadlock situation, processes that are children in
     the middle of a vfork() are never sent SIGTTOU or SIGTTIN signals;
     rather, output or ioctl(2) calls are allowed and input attempts result in
     an end-of-file indication.

HISTORY
     The vfork function call appeared in 3.0BSD.

4th Berkeley Distribution     September 14, 2000			     2
[top]

List of man pages available for BSDi

Copyright (c) for man pages and the logo by the respective OS vendor.

For those who want to learn more, the polarhome community provides shell access and support.

[legal] [privacy] [GNU] [policy] [cookies] [netiquette] [sponsors] [FAQ]
Tweet
Polarhome, production since 1999.
Member of Polarhome portal.
Based on Fawad Halim's script.
....................................................................
Vote for polarhome
Free Shell Accounts :: the biggest list on the net