Re: Basic Fork Question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 4/18/06, Niklaus <niklaus@xxxxxxxxx> wrote:
> On 4/17/06, Gaurav Dhiman <gauravd.chd@xxxxxxxxx> wrote:
> > On 4/17/06, Asim Kadav <linkasim@xxxxxxxxx> wrote:
> > > Hi,
> > >
> > > Process A has a memory allocated and memory pointer x pointing to that memory.
> > > I fork process B from a running process A.B gets a new copy of the
> > > memory and the pointer.However, printing x in A and B points to the
> > > same memory location(though actually differnt physical memory
> > > locations).What is the concept of VM here.Can anyone kindly explain ?
> >
> > The address you are seeing here are the virtual address not the
> > physical address. Virtual address are mapped to physical address
> > through page table and page directory structures which are different
> > for every process.  The virtual address you are seeing is 32 bit
> > address, this is divided into three parts, first 10 bits tells the
> > index into page directory whose base address is stored in CR3 register
> > of processor in i386 architecture. From this index we get the base
> > address of concerned page table. Next 10 bits of virtual address is
> > the index into page table whose base address we just got from page
> > directory. Now at this index in page table we get the base address of
> > the physical page we are concerned with. Now last 12 bits of virtual
> > address is an offset into this physical address. This is how the
> > virtual address is converted to physical address.
> >
> If the virtual address are same , then how can the physical address be
> different. Can you give some examples please. I am not clear about
> that.

I explained this in detail in my last mail on this thread.

Gaurav

>
> > So when you are printing the address of a varaible in your parent and
> > child process, both have same virtual address, but are actually mapped
> > to two different physical addresses through their own page table.
> >
> > Hope this explanation helps you.
> >
> > regards,
> > Gaurav
> >
> >
> > >
> > > =======================
> > > For eg. :
> > >
> > > [root@XXXXX]# cat test.c
> > > #include <stdio.h>
> > >
> > > main ()
> > > {
> > >         char a;
> > >         a='b';
> > >         fork();
> > >         a='c';
> > >         printf ("%x\n",&a);
> > > }
> > >
> > >
> > > [root@XXXXXX]# ./a.out
> > > bfed3237
> > > bfed3237
> > >
> > > Thanks,
> > > Link
> > >
> > > --
> > > Kernelnewbies: Help each other learn about the Linux kernel.
> > > Archive:       http://mail.nl.linux.org/kernelnewbies/
> > > FAQ:           http://kernelnewbies.org/faq/
> > >
> > >
> >
> >
> > --
> > --
> > -Gaurav
> > Email: gauravd.chd@xxxxxxxxx
> > ---------------------------------
> > Read my blog at: http://lkdp.blogspot.com/
> > ---------------------------------
> >
> > --
> > Kernelnewbies: Help each other learn about the Linux kernel.
> > Archive:       http://mail.nl.linux.org/kernelnewbies/
> > FAQ:           http://kernelnewbies.org/faq/
> >
> >
>


--
--
-Gaurav
Email: gauravd.chd@xxxxxxxxx
---------------------------------
Read my blog at: http://lkdp.blogspot.com/
---------------------------------

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/



[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux