Connecting Tech Pros Worldwide Help | Site Map

Forking !

  #1  
Old January 17th, 2008, 10:05 AM
harishashim@gmail.com
Guest
 
Posts: n/a
I sure hope this question is relevent to comp.lang.c++ . I have my
doubt but here I go!

I have very code that do as follows


pid_t pId = fork();

//Very large body of code
codeline1();
codeline2();
codeline3();
//etc etc etc

if (pId == 0) {

//child codes

}else if (pId < 0 ) {

//some error codes

}else {

//parent codes

}

My question is codeline1(), codeline2() and codeline3(). Are they
executed by the parent children or both?

Any comments?

Thanks In Advance!
  #2  
Old January 17th, 2008, 10:35 AM
Michael DOUBEZ
Guest
 
Posts: n/a

re: Forking !


harishashim@gmail.com a écrit :
Quote:
I sure hope this question is relevent to comp.lang.c++ . I have my
doubt but here I go!
It isn't. fork() is POSIX specific.
Quote:
>
I have very code that do as follows
>
>
pid_t pId = fork();
>
//Very large body of code
codeline1();
codeline2();
codeline3();
//etc etc etc
>
if (pId == 0) {
>
//child codes
>
}else if (pId < 0 ) {
>
//some error codes
>
}else {
>
//parent codes
>
}
>
My question is codeline1(), codeline2() and codeline3(). Are they
executed by the parent children or both?
Both.
Quote:
>
Any comments?
I find it strange that you check for the error case so late (usually a
memory matter, so it is rather important) and I would also question the
interest of having instructions execution duplicated in the fater and
the child when you don't know if it successful or in with process you are.

Michael
  #3  
Old January 17th, 2008, 10:55 AM
harishashim@gmail.com
Guest
 
Posts: n/a

re: Forking !


Quote:
Quote:
Any comments?
>
I find it strange that you check for the error case so late (usually a
memory matter, so it is rather important) and I would also question the
interest of having instructions execution duplicated in the fater and
the child when you don't know if it successful or in with process you are.
>
Michael
Thanks for the reply. I am maintaining old codes.

If it is executed by both than I have a reason to cry foul and point
out that it is a bug.

Thanks again!
Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Not forking? Gilles Ganault answers 2 November 30th, 2007 04:25 AM
PHP CLI & Forking children qwertycat@googlemail.com answers 10 October 4th, 2007 04:25 PM
forking a process felixfix@gmail.com answers 3 November 15th, 2005 03:27 AM
Forking Server SRam answers 0 July 19th, 2005 05:42 AM
forking smtpd Eric S. Johansson answers 0 July 18th, 2005 03:10 PM