GATE CS 2024 Set 1 | Question 57
Operating Systems › Introduction & Process Management · NAT · 2 marks · Answer: 14
- 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 tofork()doubles the number of processes, and each process prints once per iteration:
Total printf .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
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 →