MirBSD manpage: rfork(2)

RFORK(2)                   BSD Programmer's Manual                    RFORK(2)


     rfork - control new processes


     #include <sys/param.h>
     #include <unistd.h>

     rfork(int flags);


     The fork functions (fork(2), vfork(2), and rfork()) create new processes.
     The new process (child process) is an exact copy of the calling process
     (parent process), except as outlined in the fork(2) manual page. rfork()
     is used to manipulate the resources of the parent process and the child

     Operations currently supported include whether to copy or share the file
     descriptor table between the two processes, whether to share the address
     space, and whether the parent should wait(2) for the child process to
     _exit(2). rfork() takes a single argument, flags, which controls which of
     these resources should be manipulated. They are defined in the header
     file <sys/param.h> and are the logical OR of one or more of the follow-

     RFFDG     Copy the parent's file descriptor table. If this flag is unset,
               the parent and child will share the parent's file descriptor
               table. Descriptors will remain in existence until they are
               closed by all child processes using the table copies as well as
               by the parent process. May not be used in conjunction with

     RFPROC    Create a new process. The current implementation requires this
               flag to always be set.

     RFMEM     Force sharing of the entire address space between the parent
               and child processes. The child will then inherit all the shared
               segments the parent process owns. Subsequent forks by the
               parent will then propagate the shared data and BSS segments
               among children.

     RFNOWAIT  Child processes will have their resources reaped immediately
               and implicitly when they terminate instead of turning into zom-
               bies, so the parent process may not call wait(2) to collect
               their exit statuses and have their resources released explicit-

     RFCFDG    Zero the child's file descriptor table (i.e. start with a blank
               file descriptor table). May not be used in conjunction with

     fork(2) can be implemented as a call to rfork() using "RFFDG|RFPROC", but
     isn't for backwards compatibility. If a process has file descriptor table
     sharing active, setuid or setgid programs will not execve(2) with extra


     The parent process returns the process ID (PID) of the child process. The
     child process returns 0. The range of the process ID is defined in
     <sys/proc.h> and is currently between 1 and 32766, inclusive.


     rfork() will fail and no child process will be created if:

     [ENOMEM]      Cannot allocate memory. The new process image required more
                   memory than was allowed by the hardware or by system-
                   imposed memory management constraints. A lack of swap space
                   is normally temporary; however, a lack of core is not. Soft
                   limits may be increased to their corresponding hard limits.

     [EINVAL]      Invalid argument. Some invalid argument was supplied.

     [EAGAIN]      Resource temporarily unavailable. The system-imposed limit
                   on the total number of processes under execution would be
                   exceeded. This limit is configuration-dependent.

     [EAGAIN]      Resource temporarily unavailable. The system-imposed limit
                   MAXUPRC on the total number of processes under execution by
                   a single user would be exceeded. MAXUPRC is currently de-
                   fined in <sys/param.h> as CHILD_MAX, which is currently de-
                   fined as 80 in <sys/syslimits.h>.


     _exit(2), execve(2), fork(2), intro(2), vfork(2)


     The rfork() function first appeared in Plan 9.

MirBSD #10-current              June 17, 2003                                1

Generated on 2022-12-24 01:00:14 by $MirOS: src/scripts/roff2htm,v 1.113 2022/12/21 23:14:31 tg Exp $ — This product includes material provided by mirabilos.

These manual pages and other documentation are copyrighted by their respective writers; their sources are available at the project’s CVSweb, AnonCVS and other mirrors. The rest is Copyright © 2002–2022 MirBSD.

This manual page’s HTML representation is supposed to be valid XHTML/1.1; if not, please send a bug report — diffs preferred.

Kontakt / Impressum & Datenschutzerklärung