Copy-on-Write

Suppose that a process created a child process using the fork() system call. As we remember from slide 22 of Topic 4 on processes, this will cause a new process to be created in memory, and its memory chunk will be identical to this of the parent.

Having learned the tool of virtual memory, we realize that we can eliminate the full copy of the parent's memory section to the child's memory section. We could decide to only copy those pages in the child process that differ (after a change was made) from those of the parent. This technique is called Copy-on-Write.

Since in many cases, we call the exec() system call right after fork(), this technique is actually very useful (since the pages of the child process won't get to change prior to calling exec().) Recall that exec() will replace the memory section that was copied (or not copied) from the parent by the original code, data, stack, etc. of the child process.