Library /sys$common/syshlp/helplib.hlb  —  CRTL  vfork
    Creates an independent child process. This function is
    nonreentrant.

    Format

      #include  <unistd.h>

      int vfork  (void); (_DECC_V4_SOURCE)

      pid_t vfork  (void); (not _DECC_V4_SOURCE)

1  –  Description

    The vfork function provided by VSI C for OpenVMS
    Systems differs from the fork function provided by other C
    implementations. The vfork and fork Functions shows the two major
    differences.

    Table REF-12 The vfork and fork Functions

    The vfork Function    The fork Function

    Used with the exec    Can be used without an exec function for
    functions.            asynchronous processing.
    Creates an            Creates an exact duplicate of the parent
    independent child     process that branches at the point where
    process that shares   vfork is called, as if the parent and the
    some of               child are the same process at different
    the parent's          stages of execution.
    characteristics.

    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:

    o  It saves the return address (the address of the vfork call)
       to be used later as the return address for the call to an exec
       function.

    o  It saves the current context.

    o  It returns the integer 0 the first time it is called (before
       the call to an exec function is made). After the corresponding
       exec function call is made, the exec function returns control
       to the parent process, at the point of the vfork call, and
       it returns the process ID of the child as the return value.
       Unless the exec function fails, control appears to return
       twice from vfork even though one call was made to vfork and
       one call was made to the exec function.

    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.

    However, unlike setjmp, with vfork, all local automatic
    variables, even those with volatile-qualified type, can have
    indeterminate values if they are modified between the call to
    vfork and the corresponding call to an exec routine.

2  –  Return Values

    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.
Close Help