1,874 views
3 votes
3 votes

A process executes the following segment of code :

for(i = 1; i <= n; i++)
    fork ();
    fork ();


The number of new processes created is

2 Answers

2 votes
2 votes

1. When the loop executes, fork called n times so,

 Total no of new processes = $2^n -1$

2.Then Loop exits and next fork() executes( which is out of loop) then,

Total no of new processes becomes = 2 x $2^n -1$ =  

Example: Let n = 2 then Loop runs 2 times and fork() makes 3 new processes(exclude parent) and After the loop exits 

 Next fork() executes makes two new processes of each previous 3 new processes and one new process from parent .so, total no of new processes = 7 

Related questions

1 votes
1 votes
1 answer
1
2 votes
2 votes
2 answers
3
2 votes
2 votes
3 answers
4
Philosophical_Virus asked Dec 10, 2023
766 views
Int main (){fork();printf("a");fork();printf("b");return 0;}How many distinct outputs are possible of above code? And also give outputs