System Calls vfork(2)
vfork - spawn new process in a virtual memory efficient way
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) opera-
tion would be to create a new system 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 (either 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, however, 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() opera-
tion, since exit() will flush and close standard I/O chan-
nels, 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. Otherwise, -1 is returned to the parent
process, no child process is created, 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 deter-
mined when the system is generated.
SunOS 5.9 Last change: 14 Dec 2001 1
System Calls vfork(2)
There is insufficient swap space for the new process.
See attributes(5) for descriptions of the following attri-
| ATTRIBUTE TYPE | ATTRIBUTE VALUE |
| MT-Level | Unsafe |
exec(2), exit(2), fork(2), ioctl(2), wait(2), exit(3C),
The use of vfork() for any purpose other than as a prelude
to an immediate call to a function from the exec family or
to _exit() is not advised.
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 inherit register values from the child. This can
create problems for certain optimizing compilers if
<unistd.h> is not included in the source calling vfork().
SunOS 5.9 Last change: 14 Dec 2001 2