Question: Including the initial parent process, how many processes are created by the program? And what...

80.2K

Verified Solution

Question

Programming

Question: Including the initial parent process, how manyprocesses are created by the program? And what is the value of ibefore each process terminates? Please draw the parent-childprocess hierarchy to justify your answer.

#include

#include

int main() {

          int i =0;

          if(fork() == 0) {

                   ++i;

                    if (fork() != 0)

                            i = 3;

                    else

++i;

       fork();

         }   else   {

                     i = 5;

                     if (fork() == 0)

                                   ++i;

          }

          return 0;

}

I could really use a longer explanation of this problem. I haveseen the answer but I still don't really understand how to get tothe answer. Any help would be greatly appreciated.

Answer & Explanation Solved by verified expert
3.7 Ratings (548 Votes)
This program creates 6 processes Each process terminates whenit encounters return 0 so printing the valueof i just before that would give me the finalvalue of i for that process before the processexits so    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students