.TH fork() "" "" "System Call (libc)"
.PC "Create a new process"
.B "#include <unistd.h>"
.B "fork(\|)"
.PP
In the \*(CO system, many processes may be active simultaneously.
.B fork()
creates a new process; the new process is
a duplicate of the requesting process.
In practice, the new process often issues a
call to execute yet another new program.
.PP
The process that issues the
.B fork()
call is termed the
.I parent
process, and the newly forked process is termed the
.I child
process.
.B fork()
returns the process id of the newly created child to the parent
process, and returns zero to the child process.
The parent may call
.B wait()
to suspend itself until the child terminates.
.PP
The following
parts of the environment of a process are exactly duplicated by a
.B fork()
call:
.IP \(bu 0.3i
Open files and their seek positions
.IP \(bu
Current working and root directories
.IP \(bu
The file creation mask
.IP \(bu
The values of all signals
.IP \(bu
The alarm clock setting
.IP \(bu
Code, data, and stack segments
.PP
The system normally makes a fresh copy of the code, data, and stack segments
for the child process.
One advantage of
.I "shared text"
processes is that they do not need to copy the code segment.
It is write protected, and therefore may be shared.
.SH Example
For examples of how to use this call, see
.BR msgget() ,
.BR pipe() ,
and
.BR signal() .
.SH "See Also"
.Xr "alarm()," alarm
.Xr "execl()," execl
.Xr "exit()," exit.s
.Xr "libc," libc
.Xr "sh," sh
.Xr "umask()," umask.s
.Xr "unistd.h," unistd.h
.Xr "wait()" wait.s
.br
\*(PX Standard, \(sc3.1.1
.SH Diagnostics
.B fork()
returns \-1 on failure,
which usually involves insufficient system resources.
On successful calls,
.B fork()
returns zero to the child
and the process id of the child to the parent.
