OS & Hardware
What is the advantage of using copy-on-write when duplicating a process?
- AThe copy and the original always share whatever either one writes
- BOnly pages that get written are copied later, so it is fast and saves memory
- CEvery page is copied on each write, improving data safety
Show answer and explanation
Answer: B. Only pages that get written are copied later, so it is fast and saves memory
Copying all memory immediately when duplicating a process is slow and memory-hungry, and wasted if a new program is loaded right after. With copy-on-write, both page tables point to the same physical pages marked read-only; when either side writes, a page fault occurs and the OS copies just that page. Written data is not shared but kept separately in each process, and pages are not all copied.
- A. After a write the pages become separate and are no longer shared.
- B. Correct. Only written pages are copied, so it is fast and saves memory.
- C. Only the written page is copied.