GATE CS 2024 Set 1 | Question 57

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

  1. Question 57Operating Systemsnat2 marks
    int x=3; while(x>0){ fork(); printf("hello"); wait(NULL); x--; } The total number of times printf executes is _______

    Answer: 14

    Solution

    Answer: 14 Every call to fork() doubles the number of processes, and each process prints once per iteration:
    iteration 1 (x=3): 1 -> 2 processes, 2 printfs
    iteration 2 (x=2): 2 -> 4 processes, 4 printfs
    iteration 3 (x=1): 4 -> 8 processes, 8 printfs
    Total printf .

More GATE PYQ on Introduction & Process Management

All GATE CS Operating Systems PYQ →

Attempt GATE CS 2024 Set 1 in real GATE exam mode

Full paper with a timer, the GATE interface and a topic-wise analysis — free.

Create free account →