BSD 4_2 development
[unix-history] / usr / man / man2 / fork.2
CommitLineData
9d1cfbfb
C
1.TH FORK 2 "12 February 1983"
2.UC 4
3.SH NAME
4fork \- create a new process
5.SH SYNOPSIS
6.ft B
7pid = fork()
8.br
9int pid;
10.ft R
11.SH DESCRIPTION
12.I Fork
13causes creation of a new process.
14The new process (child process) is an exact copy of the
15calling process except for the following:
16.in +5n
17.sp
18The child process has a unique process ID.
19.sp
20The child process has a different parent process ID (i.e.,
21the process ID of the parent process).
22.sp
23The child process has its own copy of the parent's descriptors.
24These descriptors reference the same underlying objects, so that,
25for instance, file pointers in file objects are shared between
26the child and the parent, so that a
27.IR lseek (2)
28on a descriptor in the child process can affect a subsequent
29.I read
30or
31.I write
32by the parent.
33This descriptor copying is also used by the shell to
34establish standard input and output for newly created processes
35as well as to set up pipes.
36.sp
37The child processes resource utilizations are set to 0;
38see
39.IR setrlimit (2).
40.SH "RETURN VALUE
41Upon successful completion, \fIfork\fP returns a value
42of 0 to the child process and returns the process ID of the child
43process to the parent process. Otherwise, a value of \-1 is returned
44to the parent process, no child process is created, and the global
45variable \fIerrno\fP is set to indicate the error.
46.SH ERRORS
47.I Fork
48will fail and no child process will be created if one or more of the
49following are true:
50.TP 15
51[EAGAIN]
52The system-imposed limit {PROC_MAX} on the total
53number of processes under execution would be exceeded.
54.TP 15
55[EAGAIN]
56The system-imposed limit {KID_MAX} on the total number of
57processes under execution by a single user would be exceeded.
58.SH "SEE ALSO"
59execve(2), wait(2)