fork - create a new process
SYSTEM V SYNOPSIS
fork() creates a new process. The new process (child process) is an
exact copy of the calling process except for the following:
o The child process has a unique process ID. The child process ID
also does not match any active process group ID.
o The child process has a different parent process ID (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(2V)) on a descriptor in the
child process can affect a subsequent read(2V) or write(2V) by the
parent. This descriptor copying is also used by the shell to estab-
lish standard input and output for newly created processes as well
as to set up pipes.
o The child process has its own copy of the parent's open directory
streams (see directory(3V)). Each open directory stream in the
child process shares directory stream positioning with the corre-
sponding directory stream of the parent.
o All semadj values are cleared; see semop(2).
o The child processes resource utilizations are set to 0; see getr-
limit(2). The it_value and it_interval values for the ITIMER_REAL
timer are reset to 0; see getitimer(2).
o The child process's values of tms_utime(), tms_stime(),
tms_cutime(), and tms_cstime() (see times(3V)) are set to zero.
o File locks (see fcntl(2V)) previously set by the parent are not
inherited by the child.
o Pending alarms (see alarm(3V)) are cleared for the child process.
o The set of signals pending for the child process is cleared (see
On success, fork() returns 0 to the child process and returns the
process ID of the child process to the parent process. On failure,
fork() returns -1 to the parent process, sets errno to indicate the
error, and no child process is created.
fork() will fail and no child process will be created if one or more of
the following are true:
EAGAIN The system-imposed limit on the total number of pro-
cesses under execution would be exceeded. This limit is
determined when the system is generated.
The system-imposed limit on the total number of pro-
cesses under execution by a single user would be
exceeded. This limit is determined when the system is
ENOMEM There is insufficient swap space for the new process.
execve(2V), getitimer(2), getrlimit(2), lseek(2V), read(2V), semop(2),
21 January 1990 FORK(2V)