Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

exit(2)

wait2(2)

fork(2)

exec(2)



  vfork(2)                            CLIX                            vfork(2)



  NAME

    vfork - Spawns a new process so as to use virtual memory efficiently

  LIBRARY

    Berkeley Software Distribution Library (libbsd.a)

  SYNOPSIS

    int vfork(
      void );

  DESCRIPTION

    The vfork() function can be used to create new processes without fully
    copying the address space of the old process.  It is useful when the
    purpose of the fork() function would have been to create a new system
    context for an execve() function.  The vfork() function differs from
    fork() in that the child uses the parent's memory and thread of control
    until a call to the execve() function or an exit (either by a call to the
    exit() function or abnormally).  The parent process is suspended while the
    child is using its resources.

    The vfork() function returns 0 in the child's context and (later) the
    process ID of the child in the parent's context.

    The vfork() function can normally be used as fork().  However, returning
    from the procedure that called vfork() while running in the child's
    context does not work since the eventual return from vfork() by the parent
    would return to a stack frame that no longer exists.  If execve() cannot
    be called, call _exit() rather than exit(), since exit() will flush and
    close standard I/O channels and thereby corrupt the parent process's
    standard I/O data structures.  (Even with fork(), it is wrong to call
    exit() since buffered data would then be flushed twice.)

    To avoid a possible deadlock situation, processes that are children in the
    middle of a vfork() are never sent SIGTTOU or SIGTTIN signals.

  EXAMPLES

    To create a new process which immediately executes a new program:

    int vfork_retval;
    vfork_retval = vfork();

    switch(vfork_retval)

            case -1:
                    perror("Vfork failed");
                    return(-1);



  2/94 - Intergraph Corporation                                              1






  vfork(2)                            CLIX                            vfork(2)



            case 0:
                    /* Child */
              execle(program_name, arg0, (char *), envp);
              /* execle should never returns */
              perror("Execle failed\n");
              _exit(1);

            default:
                    /* Parent, vfork_retval is child's process ID */
                    ...


  RETURN VALUES

    Upon successful completion, a value of 0 is returned to the child process
    and the process ID of the child process to the parent process.  Otherwise,
    a value of -1 is returned and errno is set to indicate the error.

  ERRORS

    The vfork() function fails if the following is true:

    [EAGAIN]   The system-imposed limit on the total number of processes would
               be exceeded.  This error also occurs if the system-imposed
               limit on the total number of processes per user would be
               exceeded, or the total amount of system memory available when
               reading through raw I/O is temporarily insufficient.

  RELATED INFORMATION

    Functions:  exit(2), wait2(2), fork(2), exec(2)























  2                                              Intergraph Corporation - 2/94




Typewritten Software • bear@typewritten.org • Edmonds, WA 98026