Subhobroto Sinha wrote:

.... 
> Oh, and a quickie :
> 
> When we print an address of a variable, is it the
> virtual address or the physical one which is printed
?
....
> Look at it closely, and match it with the output.
Who
> can explain that to me ?

I am no expert on Linux memory management but even so
I feel there can be no question about it: what is
printed is the virtual address.

I have no definite explanation about why the addresses
of i in the parent and child processes appear to be
the same. (They certainly _are not_ the same, since
modifying i in the child does not modify i in the
parent.) I can only offer a guess. But it might be
useful first to read this snippet from the vfork
manpage:
<snippet>
Under  Linux,  fork()  is  implemented using
copy-on-write pages, so the only penalty incurred by
fork() is the  time and memory required to duplicate
the parent's page tables, and to create a unique task
structure for the child.  However, in the bad old days
a fork() would require making a complete copy of the 
caller's  data  space,  often needlessly,  since
usually immediately afterwards an exec() is done.
</snippet>
As it says here, the entire data space of the parent
is not duplicated for the child; instead only the page
tables are copied. And, therefore, my guess is that 
the address of i (or any other variable) as printed is
an _offset_ from some base address which we don't
know. The base address is different for the parent and

the child. This is consistent with the philosophy of
saving time: merely change the base address in the new
page tables and you have a complete new address space.

If you find an authentic explanation please share it
with me.

- Manas Laha



                
__________________________________________________________ 
Yahoo! India Matrimony: Find your partner now. Go to http://yahoo.shaadi.com


--
To unsubscribe, send mail to [EMAIL PROTECTED] with the body
"unsubscribe ilug-cal" and an empty subject line.
FAQ: http://www.ilug-cal.org/node.php?id=3

Reply via email to