Not more. There is something called COW (Copy On Write), only when one of the two processes (parent / child) tries to write to the shared data, it is copied.
In the past:
The fork() system call copied the address space of the calling process (parent) to create a new process (child). Copying the parent address space to the child was the most expensive part of the fork() operation.
Now:
The fork() call is often followed almost immediately by exec() in the child process, which replaces the child memory with a new program. This is what the shell usually does. In this case, the time taken to copy the parent address space is largely lost, because the child process will use very little of its memory before calling exec() .
For this reason, later versions of Unix used virtual memory hardware to allow parent and child users to share memory mapped to their respective address spaces until one of the processes actually changes it. This method is known as copy-on-write . To do this, in fork() kernel will copy the address space mappings from the parent to the child instead of the contents of the displayed pages, and at the same time, it will now mark read-only shared pages. When one of the two processes tries to write to one of these shared pages, the process executes the page error. At this point, the Unix kernel realizes that this page was indeed “virtual” or “copy-write”, and therefore it creates a new, private, writable copy of the page for the crash process. Thus, the contents of individual pages are not actually copied until they are written. This optimization makes fork() and then exec() much cheaper for the child: the child will probably only need to copy one page (the current page of its stack) before it calls exec() .
Tony Tannous 05 Oct '16 at 15:03 2016-10-05 15:03
source share