GATE CS 2026 Set 1 | Question 63
Operating Systems › Introduction & Process Management · NAT · 2 marks · Answer: 4
- Question 63Operating Systemsnat2 marksConsider the following program snippet. Assume that the program compiles and runs successfully. Further, assume that the fork() system call is always successful in creating a process.
The total number of times that the printf statement gets executed is ________. (answer in integer)int main () { int i; for (i = 0; i < 3; i++){ if (fork() == 0){ continue; } break; } printf("Hello!"); return 0; }Answer: 4
Solution
Answer: 4 After eachfork(), the parent breaks out of the loop and prints. The child continues and forks again, so the processes form a chain, not a tree. Each of the 4 processes prints once, so the total is 4. (A plainfork()loop without thebreakwould make .)
More GATE PYQ on Introduction & Process Management
All GATE CS Operating Systems PYQ →Attempt GATE CS 2026 Set 1 in real GATE exam mode
Full paper with a timer, the GATE interface and a topic-wise analysis — free.
Create free account →