BSD 4_3_Reno release
[unix-history] / usr / src / lib / libc / sys / fork.2
CommitLineData
2331fbb3
KM
1.\" Copyright (c) 1980 Regents of the University of California.
2.\" All rights reserved. The Berkeley software License Agreement
3.\" specifies the terms and conditions for redistribution.
4.\"
95f51977 5.\" @(#)fork.2 6.4 (Berkeley) 5/22/86
2331fbb3 6.\"
95f51977 7.TH FORK 2 "May 22, 1986"
2331fbb3
KM
8.UC
9.SH NAME
cce0de43 10fork \- create a new process
2331fbb3 11.SH SYNOPSIS
cce0de43
KM
12.ft B
13pid = fork()
14.br
15int pid;
16.ft R
2331fbb3
KM
17.SH DESCRIPTION
18.I Fork
cce0de43
KM
19causes creation of a new process.
20The new process (child process) is an exact copy of the
21calling process except for the following:
22.in +5n
23.sp
24The child process has a unique process ID.
25.sp
26The child process has a different parent process ID (i.e.,
27the process ID of the parent process).
28.sp
29The child process has its own copy of the parent's descriptors.
30These descriptors reference the same underlying objects, so that,
31for instance, file pointers in file objects are shared between
dab325d3 32the child and the parent, so that an
cce0de43
KM
33.IR lseek (2)
34on a descriptor in the child process can affect a subsequent
35.I read
36or
37.I write
38by the parent.
39This descriptor copying is also used by the shell to
40establish standard input and output for newly created processes
41as well as to set up pipes.
42.sp
43The child processes resource utilizations are set to 0;
44see
45.IR setrlimit (2).
46.SH "RETURN VALUE
47Upon successful completion, \fIfork\fP returns a value
48of 0 to the child process and returns the process ID of the child
49process to the parent process. Otherwise, a value of \-1 is returned
50to the parent process, no child process is created, and the global
51variable \fIerrno\fP is set to indicate the error.
52.SH ERRORS
53.I Fork
54will fail and no child process will be created if one or more of the
55following are true:
56.TP 15
57[EAGAIN]
dab325d3 58The system-imposed limit on the total
cce0de43 59number of processes under execution would be exceeded.
dab325d3 60This limit is configuration-dependent.
cce0de43
KM
61.TP 15
62[EAGAIN]
2bcd7f2f 63The system-imposed limit MAXUPRC (\fI<sys/param.h>) \fRon the total number of
cce0de43 64processes under execution by a single user would be exceeded.
fd690c8b
KM
65.TP 15
66[ENOMEM]
67There is insufficient swap space for the new process.
2331fbb3 68.SH "SEE ALSO"
cce0de43 69execve(2), wait(2)