1fork(2) System Calls Manual fork(2)
2
3
4
6 fork - create a child process
7
9 Standard C library (libc, -lc)
10
12 #include <unistd.h>
13
14 pid_t fork(void);
15
17 fork() creates a new process by duplicating the calling process. The
18 new process is referred to as the child process. The calling process
19 is referred to as the parent process.
20
21 The child process and the parent process run in separate memory spaces.
22 At the time of fork() both memory spaces have the same content. Memory
23 writes, file mappings (mmap(2)), and unmappings (munmap(2)) performed
24 by one of the processes do not affect the other.
25
26 The child process is an exact duplicate of the parent process except
27 for the following points:
28
29 • The child has its own unique process ID, and this PID does not match
30 the ID of any existing process group (setpgid(2)) or session.
31
32 • The child's parent process ID is the same as the parent's process
33 ID.
34
35 • The child does not inherit its parent's memory locks (mlock(2),
36 mlockall(2)).
37
38 • Process resource utilizations (getrusage(2)) and CPU time counters
39 (times(2)) are reset to zero in the child.
40
41 • The child's set of pending signals is initially empty (sigpend‐
42 ing(2)).
43
44 • The child does not inherit semaphore adjustments from its parent
45 (semop(2)).
46
47 • The child does not inherit process-associated record locks from its
48 parent (fcntl(2)). (On the other hand, it does inherit fcntl(2)
49 open file description locks and flock(2) locks from its parent.)
50
51 • The child does not inherit timers from its parent (setitimer(2),
52 alarm(2), timer_create(2)).
53
54 • The child does not inherit outstanding asynchronous I/O operations
55 from its parent (aio_read(3), aio_write(3)), nor does it inherit any
56 asynchronous I/O contexts from its parent (see io_setup(2)).
57
58 The process attributes in the preceding list are all specified in
59 POSIX.1. The parent and child also differ with respect to the follow‐
60 ing Linux-specific process attributes:
61
62 • The child does not inherit directory change notifications (dnotify)
63 from its parent (see the description of F_NOTIFY in fcntl(2)).
64
65 • The prctl(2) PR_SET_PDEATHSIG setting is reset so that the child
66 does not receive a signal when its parent terminates.
67
68 • The default timer slack value is set to the parent's current timer
69 slack value. See the description of PR_SET_TIMERSLACK in prctl(2).
70
71 • Memory mappings that have been marked with the madvise(2) MADV_DONT‐
72 FORK flag are not inherited across a fork().
73
74 • Memory in address r