11 votes 11 votes Consider the following Pseudo code main() { int t1=0,t2=0,t3=0; t1=fork(); t2=fork(); if(t1!=0) { t3=fork(); printf("0"); } } Find the total number of processes that will be created by the above program execution. Operating System operating-system fork-system-call + – neha pawar asked Oct 30, 2014 neha pawar 9.3k views answer comment Share Follow See all 8 Comments See all 8 8 Comments reply Show 5 previous comments Kaushik.P.E commented Jan 14, 2017 reply Follow Share is the total no of processes = 6 and no of child process = 5? 0 votes 0 votes Sushant Gokhale commented Jan 17, 2017 reply Follow Share Let the parent process be denoted by P. Here, the concept of copy on write is used and hence, P and C3 share the same value of t1. Now, as you can see , the processes at the leaves are P, C1, C2, C3, C4, C5 But, parent process is the process that started the program execution. they have asked No. of processed created by above program execution. How can parent process be created by above program execution? $\therefore$ No of processed created by above program excution = 5 4 votes 4 votes Chiranjeevi Kanaka commented Jan 7, 2018 reply Follow Share No. Of processes created by program is 1parent + 5child processes = 6 processes. The answer is 6, not 5. 1 votes 1 votes Please log in or register to add a comment.
1 votes 1 votes P P C P C1 C C2 P C3 C1 C4 So total 6 processes P C C1 C2 C3 C4 After first fork statement execution fork returns 0 to child and id of child to parent process P.Same happens for second fork so now 4 process are there .Now t1is not zero for P and C1 so they will execute fork..sonow there will be 6 process Pooja Palod answered Sep 21, 2015 Pooja Palod comment Share Follow See all 0 reply Please log in or register to add a comment.
1 votes 1 votes Is it correct ans total =1(Parent)+5(Child)=6 sonu answered Sep 24, 2015 sonu comment Share Follow See all 2 Comments See all 2 2 Comments reply Mojo-Jojo commented Sep 24, 2015 reply Follow Share Ans 6 is correct. 0 votes 0 votes talha hashim commented Nov 3, 2018 reply Follow Share this will be the best solution 0 votes 0 votes Please log in or register to add a comment.
0 votes 0 votes Total process will be 8 including main. Newly created child process will be 7. Since for n fork() calls total child process will be 2n - 1 IgnitorSandeep answered Sep 24, 2015 IgnitorSandeep comment Share Follow See all 2 Comments See all 2 2 Comments reply Arjun commented Sep 24, 2015 reply Follow Share Thats for n fork calls in a loop or without any intermediate condition. 1 votes 1 votes IgnitorSandeep commented Sep 24, 2015 reply Follow Share Sorry sir. It's my fault. i thought the condition is like (t1==0). Thanks for correcting me 0 votes 0 votes Please log in or register to add a comment.
0 votes 0 votes Including parent process, answer is 6 Divya Soni answered Apr 1, 2017 Divya Soni comment Share Follow See all 0 reply Please log in or register to add a comment.