Re: what will connect the fork() with its following code ? a simple example below:

2005-09-07 Thread Bernd Petrovitsch
On Tue, 2005-09-06 at 12:58 -0400, [EMAIL PROTECTED] wrote:
> On Tue, 06 Sep 2005 17:15:51 +0800, "Sat." said:
> 
> Not a kernel problem, please consult an intro-to-C list next time
> 
> > if(!(pid=fork())){
> >  ..
> >  printk("in child process");
> >  ..
> > }else{
> >  .
> >  printk("in father process"); 
> >  .
> > }
> > 
> 
> > values., and do nothing . so the bridge  between the new process and
> > its following code, printk("in child process"), seems disappear 
> 
> I'm assuming you actually meant printf() (which is the userspace stdio call)
> rather than printk() (which is the inside-the-kernel variant).

I actually assumed the same.

> 'man setbuf' - most likely the output of the child process is buffered and
> never actually output before it exits.  You want to set stdout to be

It is buffered since the above printf() lacks a terminating "\n". So
either put a "\n" at the end or call "fflush(stdout);"

> line-buffered or unbuffered, or write to stderr (unbuffered by default) rather
> than stdout. 

Bernd
-- 
Firmix Software GmbH   http://www.firmix.at/
mobil: +43 664 4416156 fax: +43 1 7890849-55
  Embedded Linux Development and Services

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: what will connect the fork() with its following code ? a simple example below:

2005-09-07 Thread Bernd Petrovitsch
On Tue, 2005-09-06 at 12:58 -0400, [EMAIL PROTECTED] wrote:
 On Tue, 06 Sep 2005 17:15:51 +0800, Sat. said:
 
 Not a kernel problem, please consult an intro-to-C list next time
 
  if(!(pid=fork())){
   ..
   printk(in child process);
   ..
  }else{
   .
   printk(in father process); 
   .
  }
  
 
  values., and do nothing . so the bridge  between the new process and
  its following code, printk(in child process), seems disappear 
 
 I'm assuming you actually meant printf() (which is the userspace stdio call)
 rather than printk() (which is the inside-the-kernel variant).

I actually assumed the same.

 'man setbuf' - most likely the output of the child process is buffered and
 never actually output before it exits.  You want to set stdout to be

It is buffered since the above printf() lacks a terminating \n. So
either put a \n at the end or call fflush(stdout);

 line-buffered or unbuffered, or write to stderr (unbuffered by default) rather
 than stdout. 

Bernd
-- 
Firmix Software GmbH   http://www.firmix.at/
mobil: +43 664 4416156 fax: +43 1 7890849-55
  Embedded Linux Development and Services

-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: what will connect the fork() with its following code ? a simple example below:

2005-09-06 Thread Valdis . Kletnieks
On Tue, 06 Sep 2005 17:15:51 +0800, "Sat." said:

Not a kernel problem, please consult an intro-to-C list next time

> if(!(pid=fork())){
>  ..
>  printk("in child process");
>  ..
> }else{
>  .
>  printk("in father process"); 
>  .
> }
> 

> values., and do nothing . so the bridge  between the new process and
> its following code, printk("in child process"), seems disappear 

I'm assuming you actually meant printf() (which is the userspace stdio call)
rather than printk() (which is the inside-the-kernel variant).

'man setbuf' - most likely the output of the child process is buffered and
never actually output before it exits.  You want to set stdout to be
line-buffered or unbuffered, or write to stderr (unbuffered by default) rather
than stdout. 



pgpqxebiu9cZm.pgp
Description: PGP signature


Re: what will connect the fork() with its following code ? a simple example below:

2005-09-06 Thread Dirk Gerdes

fork returns 0 to the child and the pid of the child to the parent.

both child and parent get the same code, so the child gets true in the 
if-statement and the parent gets false.


it would be the same as

pid = fork();
if (pid == 0){
// child
}
else{
// parent
}


- Original Message - 
From: "Sat." <[EMAIL PROTECTED]>

To: "Dirk Gerdes" <[EMAIL PROTECTED]>
Cc: 
Sent: Tuesday, September 06, 2005 1:59 PM
Subject: Re: what will connect the fork() with its following code ? a simple 
example below:



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 <[EMAIL PROTECTED]>:

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." <[EMAIL PROTECTED]>
To: 
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 [EMAIL PROTECTED]
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
>





--
Sat.

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: what will connect the fork() with its following code ? a simple example below:

2005-09-06 Thread linux-os \(Dick Johnson\)

On Tue, 6 Sep 2005, Sat. wrote:

> 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 :)
>

After the fork() system call, fork() returns the child's pid
(or an error) to the parent, and a ZERO (0) to the child. That
way the code 'knows' if the child or the parent is executing.


 switch ((pid = fork()))
 {
 case 0:// Child runs here
 printf("Child\n");
 sleep(1);
 exit(0);
 case -1:   // This is for errors
 fprintf(stderr, "fork() failed (%s)\n", strerror(errno));
 exit(1);
 default:   // The parent executes here
printf("Parent waits for child with pid %d\n", pid);
wait();
printf("Child executed with %d status\n", status >> 8);
 }

>
> 2005/9/6, Dirk Gerdes <[EMAIL PROTECTED]>:
>> 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." <[EMAIL PROTECTED]>
>> To: 
>> 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  !

sys_fork() should never be executed from inside the kernel because
it is going to copy a process' code and data. The kernel isn't a
process. To make a process from inside the kernel, you need to use:

//
//   Code to execute as a kernel thread.
//

int thread_code(void *ptr)
{
 daemonize("%s", "Kernel Thread!");
 allow_signal(SIGTERM);
 for(;;)// Run forever
 {
 do_something();

 set_current_state(TASK_INTERRUPTIBLE);
 if(signal_pending(current))
 complete_and_exit(_flag);
 }
}

//
//   Code to start the kernel thread.
//

pid = kernel_thread(thread_code, NULL, CLONE_FS|CLONE_FILES);


//
//   Code to stop the kernel thread.
//

 kill_proc(pid, SIGTERM);
 wait_for_completion(_flag);


>>>
>>>
>>>
>>> --
>>> Sat.



Cheers,
Dick Johnson
Penguin : Linux version 2.6.13 on an i686 machine (5589.54 BogoMips).
Warning : 98.36% of all statistics are fiction.
.
I apologize for the following. I tried to kill it with the above dot :


The information transmitted in this message is confidential and may be 
privileged.  Any review, retransmission, dissemination, or other use of this 
information by persons or entities other than the intended recipient is 
prohibited.  If you are not the intended recipient, please notify Analogic 
Corporation immediately - by replying to this message or by sending an email to 
[EMAIL PROTECTED] - and destroy all copies of this information, including any 
attachments, without reading or disclosing them.

Thank you.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: what will connect the fork() with its following code ? a simple example below:

2005-09-06 Thread Sat.
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 <[EMAIL PROTECTED]>:
> 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." <[EMAIL PROTECTED]>
> To: 
> 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 [EMAIL PROTECTED]
> > More majordomo info at  http://vger.kernel.org/majordomo-info.html
> > Please read the FAQ at  http://www.tux.org/lkml/
> >
> 
> 


-- 
Sat.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: what will connect the fork() with its following code ? a simple example below:

2005-09-06 Thread Bernd Petrovitsch
On Tue, 2005-09-06 at 17:15 +0800, Sat. wrote:
> 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

No, it is the same point as in the parent process - just the fork()
call. In fact the fork() returns twice - once within the parent process
(returning as result the pid of the child) and once within the child
(returning 0) [ and we ignore the error case for simplicity ].
Basically you are not forced to do a if() or switch() on the return
value(s) of fork()
  snip  
printf("1. fork() in process %d returned %d\n", getpid(), fork());
printf("2. fork() in process %d returned %d\n", getpid(), fork());
printf("3. fork() in process %d returned %d\n", getpid(), fork());
printf("4. fork() in process %d returned %d\n", getpid(), fork());
printf("5. fork() in process %d returned %d\n", getpid(), fork());
  snip  
Put this in a main() function and try it out.

> 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 ?

The kernel doesn't know (or care) about the C code (e.g. if(), ...) in
your application.
The "pointer" (if you want to call it) is the normal instruction pointer
(or what else it is called on your CPU).

> very confused :( 

Bernd
-- 
Firmix Software GmbH   http://www.firmix.at/
mobil: +43 664 4416156 fax: +43 1 7890849-55
  Embedded Linux Development and Services

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: what will connect the fork() with its following code ? a simple example below:

2005-09-06 Thread Bernd Petrovitsch
On Tue, 2005-09-06 at 17:15 +0800, Sat. wrote:
 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

No, it is the same point as in the parent process - just the fork()
call. In fact the fork() returns twice - once within the parent process
(returning as result the pid of the child) and once within the child
(returning 0) [ and we ignore the error case for simplicity ].
Basically you are not forced to do a if() or switch() on the return
value(s) of fork()
  snip  
printf(1. fork() in process %d returned %d\n, getpid(), fork());
printf(2. fork() in process %d returned %d\n, getpid(), fork());
printf(3. fork() in process %d returned %d\n, getpid(), fork());
printf(4. fork() in process %d returned %d\n, getpid(), fork());
printf(5. fork() in process %d returned %d\n, getpid(), fork());
  snip  
Put this in a main() function and try it out.

 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 ?

The kernel doesn't know (or care) about the C code (e.g. if(), ...) in
your application.
The pointer (if you want to call it) is the normal instruction pointer
(or what else it is called on your CPU).

 very confused :( 

Bernd
-- 
Firmix Software GmbH   http://www.firmix.at/
mobil: +43 664 4416156 fax: +43 1 7890849-55
  Embedded Linux Development and Services

-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: what will connect the fork() with its following code ? a simple example below:

2005-09-06 Thread Sat.
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 [EMAIL PROTECTED]:
 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. [EMAIL PROTECTED]
 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 [EMAIL PROTECTED]
  More majordomo info at  http://vger.kernel.org/majordomo-info.html
  Please read the FAQ at  http://www.tux.org/lkml/
 
 
 


-- 
Sat.
-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: what will connect the fork() with its following code ? a simple example below:

2005-09-06 Thread linux-os \(Dick Johnson\)

On Tue, 6 Sep 2005, Sat. wrote:

 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 :)


After the fork() system call, fork() returns the child's pid
(or an error) to the parent, and a ZERO (0) to the child. That
way the code 'knows' if the child or the parent is executing.


 switch ((pid = fork()))
 {
 case 0:// Child runs here
 printf(Child\n);
 sleep(1);
 exit(0);
 case -1:   // This is for errors
 fprintf(stderr, fork() failed (%s)\n, strerror(errno));
 exit(1);
 default:   // The parent executes here
printf(Parent waits for child with pid %d\n, pid);
wait(status);
printf(Child executed with %d status\n, status  8);
 }


 2005/9/6, Dirk Gerdes [EMAIL PROTECTED]:
 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. [EMAIL PROTECTED]
 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  !

sys_fork() should never be executed from inside the kernel because
it is going to copy a process' code and data. The kernel isn't a
process. To make a process from inside the kernel, you need to use:

//
//   Code to execute as a kernel thread.
//

int thread_code(void *ptr)
{
 daemonize(%s, Kernel Thread!);
 allow_signal(SIGTERM);
 for(;;)// Run forever
 {
 do_something();

 set_current_state(TASK_INTERRUPTIBLE);
 if(signal_pending(current))
 complete_and_exit(exit_flag);
 }
}

//
//   Code to start the kernel thread.
//

pid = kernel_thread(thread_code, NULL, CLONE_FS|CLONE_FILES);


//
//   Code to stop the kernel thread.
//

 kill_proc(pid, SIGTERM);
 wait_for_completion(exit_flag);





 --
 Sat.



Cheers,
Dick Johnson
Penguin : Linux version 2.6.13 on an i686 machine (5589.54 BogoMips).
Warning : 98.36% of all statistics are fiction.
.
I apologize for the following. I tried to kill it with the above dot :


The information transmitted in this message is confidential and may be 
privileged.  Any review, retransmission, dissemination, or other use of this 
information by persons or entities other than the intended recipient is 
prohibited.  If you are not the intended recipient, please notify Analogic 
Corporation immediately - by replying to this message or by sending an email to 
[EMAIL PROTECTED] - and destroy all copies of this information, including any 
attachments, without reading or disclosing them.

Thank you.
-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: what will connect the fork() with its following code ? a simple example below:

2005-09-06 Thread Dirk Gerdes

fork returns 0 to the child and the pid of the child to the parent.

both child and parent get the same code, so the child gets true in the 
if-statement and the parent gets false.


it would be the same as

pid = fork();
if (pid == 0){
// child
}
else{
// parent
}


- Original Message - 
From: Sat. [EMAIL PROTECTED]

To: Dirk Gerdes [EMAIL PROTECTED]
Cc: linux-kernel@vger.kernel.org
Sent: Tuesday, September 06, 2005 1:59 PM
Subject: Re: what will connect the fork() with its following code ? a simple 
example below:



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 [EMAIL PROTECTED]:

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. [EMAIL PROTECTED]
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 [EMAIL PROTECTED]
 More majordomo info at  http://vger.kernel.org/majordomo-info.html
 Please read the FAQ at  http://www.tux.org/lkml/






--
Sat.

-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: what will connect the fork() with its following code ? a simple example below:

2005-09-06 Thread Valdis . Kletnieks
On Tue, 06 Sep 2005 17:15:51 +0800, Sat. said:

Not a kernel problem, please consult an intro-to-C list next time

 if(!(pid=fork())){
  ..
  printk(in child process);
  ..
 }else{
  .
  printk(in father process); 
  .
 }
 

 values., and do nothing . so the bridge  between the new process and
 its following code, printk(in child process), seems disappear 

I'm assuming you actually meant printf() (which is the userspace stdio call)
rather than printk() (which is the inside-the-kernel variant).

'man setbuf' - most likely the output of the child process is buffered and
never actually output before it exits.  You want to set stdout to be
line-buffered or unbuffered, or write to stderr (unbuffered by default) rather
than stdout. 



pgpqxebiu9cZm.pgp
Description: PGP signature