ISRO | ISRO CS 2018 | Question 63
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.
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.