SCCS id got lost along the way
[unix-history] / usr / src / lib / libc / sys / fork.2
CommitLineData
931b8415
CL
1.\" Copyright (c) 1980, 1991 Regents of the University of California.
2.\" All rights reserved.
2331fbb3 3.\"
931b8415 4.\" %sccs.include.redist.man%
2331fbb3 5.\"
931b8415
CL
6.\" @(#)fork.2 6.5 (Berkeley) %G%
7.\"
8.Dd
9.Dt FORK 2
10.Os BSD 4.0
11.Sh NAME
12.Nm fork
13.Nd create a new process
14.Sh SYNOPSIS
15.Fd #include <unistd.h>
16.Ft pid_t
17.Fn fork void
18.Sh DESCRIPTION
19.Fn Fork
cce0de43
KM
20causes creation of a new process.
21The new process (child process) is an exact copy of the
931b8415
CL
22calling process (parent process) except for the following:
23.Bl -bullet -offset indent
24.It
cce0de43 25The child process has a unique process ID.
931b8415
CL
26.It
27The child process has a different parent
28process ID (i.e., the process ID of the parent process).
29.It
cce0de43
KM
30The child process has its own copy of the parent's descriptors.
31These descriptors reference the same underlying objects, so that,
32for instance, file pointers in file objects are shared between
dab325d3 33the child and the parent, so that an
931b8415 34.Xr lseek 2
cce0de43 35on a descriptor in the child process can affect a subsequent
931b8415 36.Xr read
cce0de43 37or
931b8415 38.Xr write
cce0de43
KM
39by the parent.
40This descriptor copying is also used by the shell to
41establish standard input and output for newly created processes
42as well as to set up pipes.
931b8415
CL
43.It
44The child processes resource utilizations
45are set to 0; see
46.Xr setrlimit 2 .
47.El
48.Sh RETURN VALUES
49Upon successful completion,
50.Fn fork
51returns a value
cce0de43 52of 0 to the child process and returns the process ID of the child
931b8415 53process to the parent process. Otherwise, a value of -1 is returned
cce0de43 54to the parent process, no child process is created, and the global
931b8415
CL
55variable
56.Va errno
57is set to indicate the error.
58.Sh ERRORS
59.Fn Fork
60will fail and no child process will be created if:
61.Bl -tag -width [EAGAIN]
62.It Bq Er EAGAIN
dab325d3 63The system-imposed limit on the total
cce0de43 64number of processes under execution would be exceeded.
dab325d3 65This limit is configuration-dependent.
931b8415
CL
66.It Bq Er EAGAIN
67The system-imposed limit
68.Dv MAXUPRC
69.Pq Aq Pa sys/param.h
70on the total number of
cce0de43 71processes under execution by a single user would be exceeded.
931b8415 72.It Bq Er ENOMEM
fd690c8b 73There is insufficient swap space for the new process.
931b8415
CL
74.El
75.Sh SEE ALSO
76.Xr execve 2 ,
77.Xr wait 2
78.Sh HISTORY
79A
80.Nm
81function call appeared in Version 6 AT&T UNIX.