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

NAME

6       fork - create a child process
7

SYNOPSIS

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

DESCRIPTION

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