[LCP]A small doubt on fork

Andrew Weaver Andrew.Weaver at tecnomen.fi
Fri Oct 19 19:08:48 UTC 2001


Because the addresses you are seeing are relative (ie "Offsets") to each
process, not absolute memory addresses.

> -----Original Message-----
> From:	sasidhar p [SMTP:psasidhar at hotmail.com]
> Sent:	Friday, October 19, 2001 11:23 AM
> To:	linuxcprogramming at lists.linux.org.au
> Subject:	[LCP]A small doubt on fork
> 
> Hi,
>    The result of the following program is surprising me...
> 
> main()
> {
>     int pid;
>     int i = 5;
> 
>     switch (pid = fork()) {
>          case 0 : {
>                         i = 7;
>                         printf("In child address of i = %p \n",&i);
>                       } break;
>          case -1 : printf("Fork error \n"); break;
>          default : printf("In parent address of i = %p\n",&i);
>     }
> }
> 
> Out put on my m/c:
> 
> 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?
> 
> Thanx,
> Sasi.
> 
> 
> _________________________________________________________________
> Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp
> 
> _______________________________________________
> This is the Linux C Programming List
> :  http://lists.linux.org.au/listinfo/linuxcprogramming List



More information about the linuxCprogramming mailing list