Creates an independent child process. This function is nonreentrant.
#include <unistd.h> int vfork (void);
The vfork Function | The fork Function |
---|---|
Used with the exec functions. | Can be used without an exec function for asynchronous processing. |
Creates an independent child process that shares some of the parent's characteristics. | Creates an exact duplicate of the parent process that branches at the point where vfork is called, as if the parent and the child are the same process at different stages of execution. |
The vfork function provides the setup necessary for a subsequent call to an exec function. Although no process is created by vfork, it performs the following steps:
The behavior of the vfork function is similar to the behavior of the setjmp function. Both vfork and setjmp establish a return address for later use, both return the integer 0 when they are first called to set up this address, and both pass back the second return value as though it were returned by them rather than by their corresponding exec or longjmp function calls.
On OpenVMS VAX systems, however, vfork differs from setjmp in the following way: with vfork, all local automatic variables have indeterminate values if they are modified between the call to vfork and the corresponding call to an exec routine.
0 | Indicates successful creation of the context. |
nonzero | Indicates the process ID (PID) of the child process. |
-1 | Indicates an error - failure to create the child process. |