Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I still don't really follow what point you're trying to make, but you don't seem to get getting how forking and virtual memory works.

Consider a process which uses two int/pointer sized memory locations. One contains a value, and the second contains a pointer to the first:

virtual value address 0x10000 0x12345678 0x10008 0x10000
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:
physical virtual value address address parent 0x2220000 0x10000 0x12345678 0x2220008 0x10008 0x10000 child 0x4440000 0x10000 0x12345678 0x4440008 0x10008 0x10000
After the child modifies the value, you get this:
parent 0x2220000 0x10000 0x12345678 0x2220008 0x10008 0x10000 child 0x4440000 0x10000 0xdeadbeef 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.

Dave.


In reply to Re^3: Perl forked processes and variable sharing by dave_the_m
in thread Perl forked processes and variable sharing by fireblood

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (1)
As of 2024-04-15 11:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found