Linux process...

beginner_h4x3r <[email protected]>
Newsgroups org.kernel.vger.linux-c-programming
Message-ID <[email protected]>
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 <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>

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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.