Hi.
I have a simple questions for Linux programmers. I am a C++ programmers, but I have no experience working with multithreaded programming in Linux. I would like to understand fork().
For example, how many processes including main process does the following code produces?
The code above will spawn a total of five processes including main. Is that accurate?Code:// p -> one child process int main() { fork(); // p fork(); // p fork(); // p fork(); // p return 0;
Secondly, I would like to know let say when you spawn a process using fork() I know the child-process will execute at that very instance and all the code after it. What if you spawn one child-process after another, does the total number of processes increases exponantially?
Lastly, if you spawn a child-process inside an if statement, will the child-process execute code outside of the if statement?
Thanks,Code:int main() { fork(); // If child-process, then execute. // fork() returns 0 for the child-process. if (!forker()_ { ... } cout << "will the child-process execute this line?"; return 0; }
Kuphryn



LinkBack URL
About LinkBacks


