in reply to Re^2: Perl forked processes and variable sharing
in thread Perl forked processes and variable sharing
Consider a process which uses two int/pointer sized memory locations. One contains a value, and the second contains a pointer to the first:
Those are virtual addresses - those are the addresses the process sees, and which are printed out in things like SCALAR(0x10000). The CPU's hardware behind the scenes maps that page of address space for that process to some physical page in RAM. This is all behind the scenes - you never get to see physical addresses. After the fork, the child process gets a *copy* of the parents address space - same virtual address locations, but mapping to a different physical page of memory which contains a copy of the values:virtual value address 0x10000 0x12345678 0x10008 0x10000
After the child modifies the value, you get this:physical virtual value address address parent 0x2220000 0x10000 0x12345678 0x2220008 0x10008 0x10000 child 0x4440000 0x10000 0x12345678 0x4440008 0x10008 0x10000
There is absolutely no connection between the parent and child aside from the fact that initially the child's value in its memory is a copy of the parent's. If you think your code shows shows something else, please say which exact line of output shows this, and what you think its output should be.parent 0x2220000 0x10000 0x12345678 0x2220008 0x10008 0x10000 child 0x4440000 0x10000 0xdeadbeef 0x4440008 0x10008 0x10000
Dave.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^4: Perl forked processes and variable sharing
by LanX (Saint) on Feb 02, 2022 at 11:46 UTC |