Following a fork() call in Linux, two processes (one being a child of the other) will share allocated heap memory. These allocated pages are marked COW (copy-on-write) and will remain shared until either process modifies them. At this point, they are copied, but the virtual address pointers referencing them remain the same. How can the MMU (memory management unit) distinguish between the two? Consider the following:
- Process A is started
- Process A is allocated a memory page, pointed to by the virtual address 0x1234
- Process A fork()s, spawning process B
- Process A and B now share virtual address 0x1234, pointing to the same physical memory location
- Process B modifies its 0x1234 memory page
- This memory page is copied and then modified
- Process A and B both have virtual address 0x1234, but this points to different physical memory addresses
How can this be distinguished?