1FORK(2) System Calls Manual FORK(2)
2
3
4
6 fork - create a new process
7
9 pid = fork()
10 int pid;
11
13 Fork causes creation of a new process. The new process (child process)
14 is an exact copy of the calling process except for the following:
15
16 The child process has a unique process ID.
17
18 The child process has a different parent process ID (i.e., the
19 process ID of the parent process).
20
21 The child process has its own copy of the parent's descriptors.
22 These descriptors reference the same underlying objects, so that,
23 for instance, file pointers in file objects are shared between the
24 child and the parent, so that an lseek(2) on a descriptor in the
25 child process can affect a subsequent read or write by the parent.
26 This descriptor copying is also used by the shell to establish
27 standard input and output for newly created processes as well as
28 to set up pipes.
29
30 The child processes resource utilizations are set to 0; see setr‐
31 limit(2).
32
34 Upon successful completion, fork returns a value of 0 to the child
35 process and returns the process ID of the child process to the parent
36 process. Otherwise, a value of -1 is returned to the parent process,
37 no child process is created, and the global variable errno is set to
38 indicate the error.
39
41 Fork will fail and no child process will be created if one or more of
42 the following are true:
43
44 [EAGAIN] The system-imposed limit on the total number of pro‐
45 cesses under execution would be exceeded. This limit is
46 configuration-dependent.
47
48 [EAGAIN] The system-imposed limit MAXUPRC (<sys/param.h>) on the
49 total number of processes under execution by a single
50 user would be exceeded.
51
52 [ENOMEM] There is insufficient swap space for the new process.
53
55 execve(2), wait(2)
56
57
58
593rd Berkeley Distribution May 22, 1986 FORK(2)