Skip to content
Related Articles

Related Articles

ISRO | ISRO CS 2018 | Question 63
  • Last Updated : 09 Jul, 2018

The following C program

main()
{
    fork() ; fork() ; printf ("yes");
}

If we execute this core segment, how many times the string yes will be printed ?
(A) Only once
(B) 2 times
(C) 4 times
(D) 8 times


Answer: (C)

Explanation: Number of times YES printed is equal to number of process created. Total Number of Processes = 2n where n is number of fork system calls. So here n = 2, 24 = 4

fork ();   // Line 1
fork ();   // Line 2

       P1      
    /     \     
  P1      C1    
 /  \    /  \   
P1  C2  C1  C3   
                

So, there are total 4 processes (3 new child processes and one original process).

Option (C) is correct.


Quiz of this Question

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :