Skip site navigation (1)Skip section navigation (2)

FreeBSD Manual Pages


home | help
vfork(2)			 System	Calls			      vfork(2)

       vfork - spawn new process in a virtual memory efficient way

       #include	<unistd.h>

       pid_t vfork(void);

       The  vfork()  function  creates new processes without fully copying the
       address space of	the old	process. This function is useful in  instances
       where  the purpose of a fork(2) operation would be to create a new sys-
       tem context for an execve() operation (see exec(2)).

       Unlike with the fork() function,	the child process borrows the parent's
       memory  and  thread of control until a call to execve() or an exit (ei-
       ther abnormally or by a call  to	 _exit()  (see	exit(2)).  The	parent
       process is suspended while the child is using its resources.

       In  a  multithreaded  application,   vfork() borrows only the thread of
       control that called vfork() in the parent; that is, the child  contains
       only one	thread.	The use	of vfork() in multithreaded applications, how-
       ever, is	not advised.

       The vfork() function can	normally be used the same way as  fork().  The
       procedure that called vfork(), however, should not return while running
       in the child's context, since the eventual return from vfork() would be
       to  a stack frame that no longer	exists.	The _exit() function should be
       used in favor of	exit(3C) if unable to perform an  execve()  operation,
       since  exit()  will  flush and close standard I/O channels, and thereby
       corrupt the parent process's standard I/O data structures. The  _exit()
       function	should be used even with fork()	to avoid flushing the buffered
       data twice.

       Upon successful completion, vfork() returns  0 to the child process and
       returns the process ID of the child process to the parent process. Oth-
       erwise, -1 is returned to the parent process, no	child process is  cre-
       ated, and errno is set to indicate the error.

       The vfork() function will fail if:

	     The  system-imposed  limit	on the total number of processes under
	     execution (either system-quality or by a single  user)  would  be
	     exceeded. This limit is determined	when the system	is generated.

	     There is insufficient swap	space for the new process.

       See attributes(5) for descriptions of the following attributes:

       |      ATTRIBUTE	TYPE	     |	    ATTRIBUTE VALUE	   |
       |MT-Level		     |Unsafe			   |

       exec(2),	exit(2), fork(2), ioctl(2), wait(2), exit(3C), attributes(5)

       The  use	of vfork() for any purpose other than as a prelude to an imme-
       diate call to a function	from the  exec family or to   _exit()  is  not

       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  ioctls are allowed and input attempts result in an
       EOF indication.

       On some systems,	the implementation of vfork() causes the parent	to in-
       herit register values from the child. This can create problems for cer-
       tain optimizing compilers if <unistd.h> is not included in  the	source
       calling vfork().

SunOS 5.9			  14 Dec 2001			      vfork(2)


Want to link to this manual page? Use this URL:

home | help