[Subject Prev][Subject Next][Thread Prev][Thread Next][Subject Index][Thread Index]

Re: [LI] C Programming problem



sudheer@xxxxxxxxxxxxx wrote:
> 
> On 4 Nov 1999, Vimal Mathew wrote:
> 
> > -
> > main()
> > {
> >       int i;
> >
> >       printf("Should appear only once");
> >       for (i = 0; i<10 ;i++) fork();
> 
> Hi,
> 
> i have a doubt regarding fork(). Even if i modify the value of 'i'
> (or any variable declared in parent) in the child and
> if i try to print the address of 'i' ,
> both child and parent shows the same address. Why is that.
> Is it because both parent and child uses same virtual address space.
> If so how it can correctly access the addressed variable(whether child
> or parent)
> 
> Please clarify
> 
> sudheer
> 
> --------------------------------------------------------------------
> The Linux India Mailing List Archives are now available.  Please search
> the archive at http://lists.linux-india.org/ before posting your question
> to avoid repetition and save bandwidth.

-- 
Hi Vimal !
	This is because fork creates an identical copy of the parent processes
and what you see as the address of a variable is within THAT process'
address space not the global memory .

HTH
Regards
Shourya
  
_______________________________________________________________
All the world's a stage..
And I am acting tonight
_______________________________________________________________
Shourya Sarcar
Student
Department of Computer Science and Engineering
Jadavpur University
Calcutta, India 700 032

Email   : sarcar@xxxxxxxx     
Tel     : 91-033-471 0477
Address : 364/3 Netaji Subhas Chandra Bose Road
	  Calcutta , India 700 047
_______________________________________________________________
C- the difference :http://www.eskimo.com/~scs/C-faq/top.html
_______________________________________________________________
--------------------------------------------------------------------
The Linux India Mailing List Archives are now available.  Please search
the archive at http://lists.linux-india.org/ before posting your question
to avoid repetition and save bandwidth.