Connecting Tech Pros Worldwide Help | Site Map

Forking !

 
LinkBack Thread Tools Search this Thread
  #1  
Old January 17th, 2008, 09:05 AM
harishashim@gmail.com
Guest
 
Posts: n/a
Default Forking !

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, 09:35 AM
Michael DOUBEZ
Guest
 
Posts: n/a
Default 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, 09:55 AM
harishashim@gmail.com
Guest
 
Posts: n/a
Default 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!
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,840 network members.