0
0
Operating Systemsknowledge~10 mins

Copy-on-write technique in Operating Systems - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Copy-on-write technique
Process A and B share same memory page
Process B tries to write to shared page
OS detects write attempt
OS creates a copy of the page for Process B
Process B writes to its own copy
Process A continues using original page
Both processes have separate pages after write
Two processes share the same memory page until one tries to write, then the OS copies the page so each has its own.
Execution Sample
Operating Systems
Process A and B share page P
Process B writes to page P
OS copies page P to P_B
Process B writes to P_B
Process A uses original P
Shows how copy-on-write delays copying memory until a write happens.
Analysis Table
StepActionMemory StateResult
1Process A and B share page PP shared by A and BNo copy, memory shared
2Process B attempts to write to PP shared by A and BWrite detected, triggers copy
3OS copies page P to P_B for Process BP owned by A, P_B owned by BSeparate copies created
4Process B writes to P_BP unchanged, P_B modifiedB's write isolated
5Process A continues using original PP unchangedA unaffected by B's write
6EndSeparate pages for A and BCopy-on-write complete
💡 Process B's write triggers copy, so both have separate pages after step 5
State Tracker
Memory PageStartAfter Step 3After Step 4Final
P (Process A)SharedOwned by AUnchangedOwned by A
P_B (Process B)N/ANew copy createdModified by BOwned by B
Key Insights - 3 Insights
Why is memory not copied when processes first share the page?
Because both processes only read the page initially, so OS saves memory by sharing until a write occurs (see step 1 in execution_table).
What triggers the OS to make a copy of the memory page?
A write attempt by one process to the shared page triggers the OS to copy it (see step 2 and 3 in execution_table).
Does the original process's memory page change after the other process writes?
No, the original process keeps using the original page unchanged (see step 5 in execution_table).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, at which step does the OS create a new copy of the memory page?
AStep 3
BStep 4
CStep 2
DStep 5
💡 Hint
Check the 'Action' and 'Result' columns in execution_table rows for step 3.
According to variable_tracker, what is the state of Process B's memory page after step 4?
AShared with Process A
BNew copy modified by Process B
CUnchanged original page
DNo memory page assigned
💡 Hint
Look at the 'P_B (Process B)' row under 'After Step 4' in variable_tracker.
If Process B never writes to the shared page, what would happen according to the concept flow?
AProcess A loses access to the page
BOS copies the page anyway
CProcesses continue sharing the same page
DBoth processes crash
💡 Hint
Refer to the first step in concept_flow where sharing continues until a write occurs.
Concept Snapshot
Copy-on-write delays copying shared memory pages until a write occurs.
Processes share pages to save memory.
When a write happens, OS copies the page for the writing process.
This keeps memory use efficient and isolated after writes.
Used in OS for process creation and memory management.
Full Transcript
Copy-on-write is a technique where two processes initially share the same memory page to save space. When one process tries to write to that page, the operating system detects this and creates a separate copy of the page for that process. This way, the writing process modifies its own copy, while the other process continues using the original page unchanged. This method avoids unnecessary copying until it is needed, making memory use more efficient. The execution steps show the shared state, the write attempt, the copying action, and the final separate pages for each process.