This is the core of fork() , and this is exactly what allows it to work. To understand this, you need to remember that the entire address space of the process in modern operating systems is virtual - this means that it has nothing to do with the actual address memory of the physical memory. Gone are the days when access to memory at 0x8000 (if I remember the address correctly) went directly to video memory. I used to program this way, and instead of screen manipulation routines, the values ββin the video memory were simply written, which was much faster. It was fun:)
But this is no longer the case. Now in user programs, the address has nothing to do with physical memory, and whenever you access memory in locaiton '0x1234567', the translation is done. The CPU knows how to map this virtual address to the address of the physical memory, but no one does.
So, when you fork your process, an exact copy of the memory is created. It has the same virtual addresses (since the memory replica is accurate!). But since this is now a process of difference, the processor will translate these virtual addresses to another addressing of the physical memory. At least that's semantics. In real modern systems, exact copying of memory does not actually occur. or fork() will take too long. Instead, the memory is marked as "copy-on-write". This means that until the data is changed, two processes will access the same physical memory. But as soon as any process changes memory, it will be actually copied, and now everyone will have their own copy.
source share