[LCP]A small doubt on fork

Bradley, Peter PBradley at uwic.ac.uk
Sat Oct 20 01:27:35 UTC 2001


Thanks for this thread.  I've certainly learnt something.

Peter

 -----Original Message-----
From: 	Bill Rausch [mailto:bill at numerical.com] 
Sent:	19 October 2001 15:58
To:	linuxcprogramming at lists.linux.org.au
Cc:	sasidhar p
Subject:	Re: [LCP]A small doubt on fork

In a multi-process, virtual memory system like Linux (or other 
UNIX-like systems), each process has its own complete address space. 
Therefore each process has its own location zero, it own location 
one, etc. up to the maximum size of its addressable memory.

Each of these virtual address spaces is surprisingly large and most 
of it never gets used. Write a recursive function sometime and print 
out the address of a local variable. Now write a function that calls 
malloc in a loop and print out those addresses. Print out the 
addresses of some global variables. You'll see that these are all 
very different than each other, often a much larger range than the 
amount of actual memory/swap space you have configured for your 
system. This works because the virtual memory management system 
allows unused "holes" inside of the address space. It only really 
needs to allocate the actual pieces you are using as you need them, 
not the whole thing in advance.

At runtime, the virtual addresses are translated into real physical 
addresses (which we never see as application programmers).


At 1:52 PM +0530 10/19/01, sasidhar p wrote:
>Hi,
>   The result of the following program is surprising me...
>...
>In parent address of i = effffa68
>In child address of i = effffa68
>
>Problem : I was expecting that the addresses shold be different 
>because fork creates a new process.  But the o/p is both addresses 
>are same.
>
>Question: Why is this so?
>

-- 
  Bill Rausch, Software Development, Unix, Mac, Windows
  Numerical Applications, Inc.  509-943-0861   bill at numerical.com
_______________________________________________
This is the Linux C Programming List
:  http://lists.linux.org.au/listinfo/linuxcprogramming List



More information about the linuxCprogramming mailing list