All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Sat." <walking.to.remember@gmail.com>
To: Dirk Gerdes <mail@dirk-gerdes.de>
Cc: linux-kernel@vger.kernel.org
Subject: Re: what will connect the fork() with its following code ? a simple example below:
Date: Tue, 6 Sep 2005 19:59:47 +0800	[thread overview]
Message-ID: <6b5347dc05090604596ac08cb6@mail.gmail.com> (raw)
In-Reply-To: <003a01c5b2d6$610d6360$6464a8c0@pc0001>

here is a snip in 0.11 version linux , 
in linux/init/main.c


179 if (!(pid=fork())) {
180 close(0);
181 if (open( "/etc/rc",O_RDONLY,0))
182 _exit(1);
183 execve( "/bin/sh",argv_rc,envp_rc); 
184 _exit(2);
185 }

natually, the code from 180 to 184 is runned by the new process, what
I can understand is why the new process know that the next code will
run is close(0) and why it know It will end at line 184 ?

so ,I feel that there should be some connection between  them . but
what the relationship in depth is ?

thanks your help :) 


2005/9/6, Dirk Gerdes <mail@dirk-gerdes.de>:
> There is no connection between a child an its parent.
> The child only gets a copy of the code.
> If there were a pointer to a child or to the parent, you wouldn't need any
> signals.
> The processes could communicate directly.
> 
> regards
> 
> ----- Original Message -----
> From: "Sat." <walking.to.remember@gmail.com>
> To: <linux-kernel@vger.kernel.org>
> Sent: Tuesday, September 06, 2005 11:15 AM
> Subject: what will connect the fork() with its following code ? a simple
> example below:
> 
> 
> > if(!(pid=fork())){
> >     ......
> >     printk("in child process");
> >     ......
> > }else{
> >     .....
> >     printk("in father process");
> >     .....
> > }
> >
> > this is a classical example, when the fork() system call runs, it will
> > build a new process and active it . while the schedule() select the
> > new process it will run. this is rather normal.
> >
> > but there is always a confusion in my minds.
> > because , sys_fork() only copies father process and configure some new
> > values., and do nothing . so the bridge  between the new process and
> > its following code, printk("in child process"), seems disappear . so I
> > always believe that the new process should have a pointer which point
> > the code "printk("in child process");". except this , there are not
> > any connection between them ?
> >
> > very confused :(
> >
> > any help will  appreciate  !
> >
> >
> >
> > --
> > Sat.
> > -
> > To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> > the body of a message to majordomo@vger.kernel.org
> > More majordomo info at  http://vger.kernel.org/majordomo-info.html
> > Please read the FAQ at  http://www.tux.org/lkml/
> >
> 
> 


-- 
Sat.

  parent reply	other threads:[~2005-09-06 11:59 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-09-06  9:15 what will connect the fork() with its following code ? a simple example below: Sat.
2005-09-06 10:37 ` Bernd Petrovitsch
     [not found] ` <003a01c5b2d6$610d6360$6464a8c0@pc0001>
2005-09-06 11:59   ` Sat. [this message]
2005-09-06 12:41     ` linux-os (Dick Johnson)
2005-09-06 13:01     ` Dirk Gerdes
2005-09-06 16:58 ` Valdis.Kletnieks
2005-09-07  7:08   ` Bernd Petrovitsch

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=6b5347dc05090604596ac08cb6@mail.gmail.com \
    --to=walking.to.remember@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mail@dirk-gerdes.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.