in reply to trying to understand references
I expected the parent to see the newly incremented value of $testVar but I don't. Why is that?
Because forked processes do not share memory. Or rather, they do not have write access to shared memory.
On systems supporting COW, child and parent will share read access to the memory, but at the point that the child attempts to modify that shared memory, it will be duplicated and then the child's copy will be modified leaving the parents's copy as it was at the fork point. That is, the memory is Copied On Write (COW).
On systems not supporting COW, parent and child will each get their own copy at the fork point.
Slightly complicating the picture is the fork emulation on Win32, which is different again.
|
|---|