Forking !

H

harishashim

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!
 
M

Michael DOUBEZ

(e-mail address removed) a écrit :
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.
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.


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
 
H

harishashim

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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,260
Messages
2,571,038
Members
48,768
Latest member
first4landlord

Latest Threads

Top