The new process created by fork is called the child process. This function is called once but returns
twice. The only difference in the returns is that the return value in the child is 0, whereas the return value in the parent is the process ID of the new child.
The reason the child's process ID is returned to the parent is that a process can have more than one child, and there is no function that allows a process to o^ain the process IDs of its children. The reason fork returns 0 to the child is that a process can
have only asingle parent, and the child can always call getppid to o^ain the process ID of its parent. (Process ID 0 is reserved for use by the kernel, so it's
not possible for 0 to be the process ID of a child.)
Both the child and the parent continue executing with the instruction that follows the call to fork. The child is a copy of the parent. For example, the child gets a copy of the parent's data space, heap, and
stack. Note that this is a copy for the child; the parent and the child do not share these portions of memory. The parent and the child share the text segment
Current implementations don't perform. a complete copy of the parent's data, stack, and heap, since a fork is often followed by an exec. Instead, a technique called copy-on-write (COW) is used. These regions
are shared by the parent and the child and have their protection changed by the kernel to read-only. If either process tries to modify these regions, the kernel then makes a copy of that piece of memory only, typically a "page" in a virtual memory system.
Section 9.2 of Bach  and Sections 5.6 and 5.7 of McKusick et al.  provide more detail on this feature.