linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: beginner_h4x3r <nightdecoder@gmail.com>
To: linux-c-programming@vger.kernel.org
Subject: Linux process...
Date: Mon, 30 Mar 2009 13:06:30 +0700	[thread overview]
Message-ID: <34e1241d0903292306m3e879639u4752e821349c84ee@mail.gmail.com> (raw)

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

             reply	other threads:[~2009-03-30  6:06 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-30  6:06 beginner_h4x3r [this message]
2009-03-30  6:15 ` Linux process Rahul K Patel
2009-03-30  6:57   ` beginner_h4x3r
2009-03-30  7:11     ` Mohana Sundaram
2009-03-30 11:36 ` Fabian Ischia
2009-03-31  1:12   ` beginner_h4x3r
2009-03-31  5:57     ` Glynn Clements
2009-03-31 23:45     ` stephan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=34e1241d0903292306m3e879639u4752e821349c84ee@mail.gmail.com \
    --to=nightdecoder@gmail.com \
    --cc=linux-c-programming@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).