vfork()

NAME

vfork() - spawn a new process efficiently, sharing virtual memory

SYNOPSIS

#include <unistd.h>

pid_t vfork(void)

DESCRIPTION

The vfork(2) call creates a new process, just as fork(2) does, but it doesn't fully copy the address space of the parent process. By sharing the space, process creation is much faster in a paged environment. Normally, vfork(2) is a faster way to create a new process before an exec-family call.

However, the greater speed has a greater risk to the parent process if the child process does not immediately exec(2) or _exit(2). (Leaving with exit(3) isn't recommened because exit(3) flushes and closes the I/O data structures of the parent.)

RETURN VALUE

On success, vfork(2) call returns with 0 to the child process and it returns the process ID of the child process to the parent process. If the call fails, it returns -1 to the parent process, does not create a new process, and sets errno to indicate the error.

ERRORS

The vfork(2) call can fail for the following reasons:

[EAGAIN]
Creating the new process would exceed the limit on running processes, either a system-wide limit or a per-user limit.
[ENOMEM]
There is not enough swap space for the new process.

SEE ALSO

exec(2)

exit(3)

fork(2)

wait(2)