GATE CS 2026 Set 1 | Question 63

Operating Systems › Introduction & Process Management · NAT · 2 marks · Answer: 4

  1. Question 63Operating Systemsnat2 marks
    Consider 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.
    int main () {
       int i;
       for (i = 0; i < 3; i++){
          if (fork() == 0){
            continue;
          }
          break;
       }
       printf("Hello!");
       return 0;
    }
    The total number of times that the printf statement gets executed is ________. (answer in integer)

    Answer: 4

    Solution

    Answer: 4 After each fork(), 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 plain fork() loop without the break would make .)
    GATE CS 2026 Set 1 Question 63 solution figure

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 →