NAME
vfork — create a
new process; share virtual memory
SYNOPSIS
pid_t vfork(void);
DESCRIPTION
The vfork () function shall be equivalent
to fork(3), except that the behavior is undefined if the
process created by vfork () either modifies any data
other than a variable of type
pid_t
used to store the return value from vfork (), or
returns from the function in which vfork () was
called, or calls any other function before successfully calling
_exit(3) or one of the exec family of
functions.
RETURN VALUE
Upon successful completion, vfork () shall
return 0 to the child process and return the process ID of the child process
to the parent process. Otherwise, -1 shall be returned to the parent, no
child process shall be created, and
errno
shall be set to indicate the error.
ERRORS
The vfork () function shall fail if:
EXAMPLES
None.
APPLICATION USAGE
Conforming applications are recommended not to depend on
vfork (), but to use fork(3)
instead. The vfork () function may be withdrawn in a
future version.
On some implementations, vfork () is
equivalent to fork(3).
The vfork () function differs from
fork(3) 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 call to a function from the
exec family, or to _exit(3), is not
advised.
The vfork () function 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 call exec,
the data space copied from the parent to the child by
fork(3) is not used. This is particularly inefficient in a
paged environment, making vfork () particularly
useful. Depending upon the size of the parent's data space,
vfork () can give a significant performance
improvement over fork(3).
The vfork () function can normally be used
just like fork(3). It does not work, however, to return
while running in the child's context from the caller of
vfork () since the eventual return from
vfork () would then return to a no longer existent
stack frame. Care should be taken, also, to call _exit(3)
rather than exit(3) if exec cannot be
used, since exit(3) flushes and closes standard I/O
channels, thereby damaging the parent process' standard I/O data structures.
(Even with fork(3), it is wrong to call
exit(3), since buffered data would then be flushed
twice.)
If signal handlers are invoked in the child process after
vfork (), they must follow the same rules as other
code in the child process.
RATIONALE
None.
FUTURE DIRECTIONS
This function may be withdrawn in a future version.
SEE ALSO
exec(3), exit(3), fork(3), wait(3), the Base Definitions volume of IEEE Std 1003.1-2001 (“POSIX.1”), <unistd.h>
CHANGE HISTORY
First released in Issue 4, Version 2.
Issue 5
Moved from X/OPEN UNIX extension to BASE.
Issue 6
This function is marked obsolescent.
End of informative text. footer end