1FORK(2)                    Linux Programmer's Manual                   FORK(2)
2
3
4

NAME

6       fork - create a child process
7

SYNOPSIS

9       #include <unistd.h>
10
11       pid_t fork(void);
12

DESCRIPTION

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