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