Commit | Line | Data |
---|---|---|
aaea5b2e KB |
1 | .\" Copyright (c) 1980, 1991, 1993 |
2 | .\" The Regents of the University of California. All rights reserved. | |
2331fbb3 | 3 | .\" |
b11a218d | 4 | .\" %sccs.include.redist.roff% |
2331fbb3 | 5 | .\" |
aaea5b2e | 6 | .\" @(#)fork.2 8.1 (Berkeley) %G% |
931b8415 CL |
7 | .\" |
8 | .Dd | |
9 | .Dt FORK 2 | |
b11a218d | 10 | .Os BSD 4 |
931b8415 CL |
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 |
20 | causes creation of a new process. |
21 | The new process (child process) is an exact copy of the | |
931b8415 CL |
22 | calling process (parent process) except for the following: |
23 | .Bl -bullet -offset indent | |
24 | .It | |
cce0de43 | 25 | The child process has a unique process ID. |
931b8415 CL |
26 | .It |
27 | The child process has a different parent | |
28 | process ID (i.e., the process ID of the parent process). | |
29 | .It | |
cce0de43 KM |
30 | The child process has its own copy of the parent's descriptors. |
31 | These descriptors reference the same underlying objects, so that, | |
32 | for instance, file pointers in file objects are shared between | |
dab325d3 | 33 | the child and the parent, so that an |
931b8415 | 34 | .Xr lseek 2 |
cce0de43 | 35 | on a descriptor in the child process can affect a subsequent |
931b8415 | 36 | .Xr read |
cce0de43 | 37 | or |
931b8415 | 38 | .Xr write |
cce0de43 KM |
39 | by the parent. |
40 | This descriptor copying is also used by the shell to | |
41 | establish standard input and output for newly created processes | |
42 | as well as to set up pipes. | |
931b8415 CL |
43 | .It |
44 | The child processes resource utilizations | |
45 | are set to 0; see | |
46 | .Xr setrlimit 2 . | |
47 | .El | |
48 | .Sh RETURN VALUES | |
49 | Upon successful completion, | |
50 | .Fn fork | |
51 | returns a value | |
cce0de43 | 52 | of 0 to the child process and returns the process ID of the child |
931b8415 | 53 | process to the parent process. Otherwise, a value of -1 is returned |
cce0de43 | 54 | to the parent process, no child process is created, and the global |
931b8415 CL |
55 | variable |
56 | .Va errno | |
57 | is set to indicate the error. | |
58 | .Sh ERRORS | |
59 | .Fn Fork | |
60 | will fail and no child process will be created if: | |
61 | .Bl -tag -width [EAGAIN] | |
62 | .It Bq Er EAGAIN | |
dab325d3 | 63 | The system-imposed limit on the total |
cce0de43 | 64 | number of processes under execution would be exceeded. |
dab325d3 | 65 | This limit is configuration-dependent. |
931b8415 CL |
66 | .It Bq Er EAGAIN |
67 | The system-imposed limit | |
68 | .Dv MAXUPRC | |
69 | .Pq Aq Pa sys/param.h | |
70 | on the total number of | |
cce0de43 | 71 | processes under execution by a single user would be exceeded. |
931b8415 | 72 | .It Bq Er ENOMEM |
fd690c8b | 73 | There 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 | |
79 | A | |
b11a218d CL |
80 | .Fn fork 2 |
81 | function call appeared in | |
82 | .At v6 . |