From mboxrd@z Thu Jan 1 00:00:00 1970 From: Rahul K Patel Subject: Re: Linux process... Date: Mon, 30 Mar 2009 11:45:58 +0530 Message-ID: <49D0639E.3060101@einfochips.com> References: <34e1241d0903292306m3e879639u4752e821349c84ee@mail.gmail.com> Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <34e1241d0903292306m3e879639u4752e821349c84ee@mail.gmail.com> Sender: linux-c-programming-owner@vger.kernel.org List-ID: Content-Type: text/plain; charset="us-ascii"; format="flowed" To: beginner_h4x3r Cc: linux-c-programming@vger.kernel.org it's offset address and not absolute address. base addresses of your parent and child process will be different so final absolute address (base + offset) will be different for both. beginner_h4x3r wrote: > Hi All.. > > I am a beginner hacker, i want to learn Linux from scratch. I read > some resources on Linux's process management. Process duplicates it's > page table to it's child process, right? so i wrote demonstrate code > to prove this. > > #include > #include > #include > #include > #include > > int main (void) { > pid_t child; > int stack_int; > > child = fork (); > if (child == 0) { > sleep (1); /* ;p */ > printf ("child process stack_int value %i, address: %p\n", > stack_int, &stack_int); > exit (0); > } > if (child == -1) { > perror ("fork"); > return -1; > } > stack_int = 32; > printf ("main process stack_int value %i, address: %p\n", stack_int, > &stack_int); > waitpid (child, NULL, 0); > > return 0; > } > > The output is: > main process stack_int value 32, address: 0xbf9c66ec > child process stack_int value 8495092, address: 0xbf9c66ec > > stack_int value is different from parent and it's child. > > My question: why the stack_int has a same address between parent and > it's child ?, but confusedly... they have a different value, i was > though it should be different, since process duplicate it's page to > child, please explain me. ;) > > Thanks before. > > --- curious_hacker > -- > To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > > > Email Scanned for Virus & Dangerous Content by : www.CleanMailGateway.com > > >