Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

fork(2) [plan9 man page]

FORK(2) 							System Calls Manual							   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 environment variables (see env(3)), the note group (the set of processes that receive notes written to a member's notepg file; see proc(3)), 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 par- ent 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. The tag space for rendezvous(2) is considered part of the 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. RFENVG If set, the environment variables are copied; otherwise the two processes share environment variables. Is mutually exclusive with RFCENVG. RFCENVG If set, the new process starts with an empty environment. 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 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. RFMEM If set, the kernel will mark segments of type data and bss as shared. The child will then inherit all the shared segments the parent process owns. Other segment types will be unaffected. Subsequent forks by the parent will then propagate the shared data and bss between children. The stack segment is always split. 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 processes 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 integer (int) value. Rfork will sleep, if necessary, until required process resources are available. Fork is just a call of rfork(RFFDG|RFPROC). SOURCE
/sys/src/libc/9syscall /sys/src/libc/9sys/fork.c SEE ALSO
intro(2), proc(3), DIAGNOSTICS
These functions set errstr. FORK(2)

Check Out this Related Man Page

FORK(2) 						      BSD System Calls Manual							   FORK(2)

NAME
fork -- create a new process SYNOPSIS
#include <sys/types.h> #include <unistd.h> pid_t fork(void); DESCRIPTION
Fork() causes creation of a new process. The new process (child process) is an exact copy of the calling process (parent process) except for the following: o The child process has a unique process ID. o The child process has a different parent process ID (i.e., the process ID of the parent process). o The child process has its own copy of the parent's descriptors. These descriptors reference the same underlying objects, so that, for instance, file pointers in file objects are shared between the child and the parent, so that an lseek(2) on a descriptor in the child process can affect a subsequent read or write by the parent. This descriptor copying is also used by the shell to establish standard input and output for newly created processes as well as to set up pipes. o The child processes resource utilizations are set to 0; see setrlimit(2). RETURN VALUES
Upon successful completion, fork() returns a value of 0 to the child process and returns the process ID of the child process to the parent process. Otherwise, a value of -1 is returned to the parent process, no child process is created, and the global variable errno is set to indicate the error. ERRORS
Fork() will fail and no child process will be created if: [EAGAIN] The system-imposed limit on the total number of processes under execution would be exceeded. This limit is configuration- dependent. [EAGAIN] The system-imposed limit MAXUPRC (<sys/param.h>) on the total number of processes under execution by a single user would be exceeded. [ENOMEM] There is insufficient swap space for the new process. SEE ALSO
execve(2), wait(2) HISTORY
A fork() function call appeared in Version 6 AT&T UNIX. 4th Berkeley Distribution June 4, 1993 4th Berkeley Distribution
Man Page