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