FORK(2)                                                   FORK(2)

     NAME
          fork, rfork - manipulate process resources

     SYNOPSIS
          #include <u.h>
          #include <libc.h>

          int fork(void)

          int rfork(int flags)

     DESCRIPTION
          Forking is the only way new processes are created.  The
          flags argument to rfork selects which resources of the
          invoking process (parent) are shared by the new process
          (child) or initialized to their default values.  The
          resources include the file name space, the open file
          descriptor table (which, when shared, permits processes to
          open and close files for other processes), the set of envi-
          ronment variables (see env(3)), the note group (the set of
          processes that receive notes written to a member's notepg
          file; see proc(3)), the set of rendezvous tags (see
          rendezvous(2)); and open files.  Flags is the logical OR of
          some subset of

          RFPROC    If set a new process is created; otherwise changes
                    affect the current process.
          RFNOWAIT  If set, the child process will be dissociated from
                    the parent. Upon exit the child will leave no
                    Waitmsg (see wait(2)) for the parent to collect.
          RFNAMEG   If set, the new process inherits a copy of the
                    parent's name space; otherwise the new process
                    shares the parent's name space.  Is mutually
                    exclusive with RFCNAMEG.
          RFCNAMEG  If set, the new process starts with a clean name
                    space. A new name space must be built from a mount
                    of an open file descriptor.  Is mutually exclusive
                    with RFNAMEG.
          RFNOMNT   If set, subsequent mounts into the new name space
                    are disallowed.  All pathnames starting with #
                    besides those used to access pipe(3), dup(3),
                    env(3), cons(3), and proc(3) can not be walked.
          RFENVG    If set, the environment variables are copied; oth-
                    erwise the two processes share environment vari-
                    ables.  Is mutually exclusive with RFCENVG.
          RFCENVG   If set, the new process starts with an empty envi-
                    ronment.  Is mutually exclusive with RFENVG.
          RFNOTEG   Each process is a member of a group of processes
                    that all receive notes when a note is written to
                    any of their notepg files (see proc(3)). The group

     Page 1                       Plan 9            (printed 11/18/24)

     FORK(2)                                                   FORK(2)

                    of a new process is by default the same as its
                    parent, but if RFNOTEG is set (regardless of
                    RFPROC), the process becomes the first in a new
                    group, isolated from previous processes.
          RFFDG     If set, the invoker's file descriptor table (see
                    intro(2)) is copied; otherwise the two processes
                    share a single table.
          RFCFDG    If set, the new process starts with a clean file
                    descriptor table.  Is mutually exclusive with
                    RFFDG.
          RFREND    If set, the process will be unable to
                    rendezvous(2) with any of its ancestors; its chil-
                    dren will, however, be able to rendezvous with it.
                    In effect, RFREND makes the process the first in a
                    group of processes that share a space for
                    rendezvous tags.
          RFMEM     If set, the child and the parent will share data
                    and bss segments.  Otherwise, the child inherits a
                    copy of those segments.  Other segment types, in
                    particular stack segments, will be unaffected.
                    May be set only with RFPROC.

          File descriptors in a shared file descriptor table are kept
          open until either they are explicitly closed or all pro-
          cesses sharing the table exit.

          If RFPROC is set, the value returned in the parent process
          is the process id of the child process; the value returned
          in the child is zero.  Without RFPROC, the return value is
          zero.  Process ids range from 1 to the maximum positive
          integer (int) value.  Rfork may also return -1 if process
          resources are exhausted.

          Fork is just a call of rfork(RFFDG|RFREND|RFPROC).

     SOURCE
          /sys/src/libc/9syscall
          /sys/src/libc/9sys/fork.c

     SEE ALSO
          intro(2), proc(3),

     DIAGNOSTICS
          These functions set errstr.

     Page 2                       Plan 9            (printed 11/18/24)