9,273 views
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. 

8 Answers

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

1 votes
1 votes

Is it correct ans

total =1(Parent)+5(Child)=6

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 2- 1

Answer:

Related questions

1 votes
1 votes
2 answers
1
1 votes
1 votes
1 answer
3
Mak Indus asked Jan 11, 2019
2,904 views
How many processes will be created when we run the below program?main ( ){Printf (“Hi”);fork ( );Printf (“Hello”);fork ( );fork ( );}(a) 3 ...