CS FundamentalsVery hardGATE CS
How many numbers are printed in total, and what is their sum? (Every fork() succeeds; output unbuffered.)
How many numbers are printed in total, and what is their sum? (Every fork() succeeds; output unbuffered.)
int main() {
for (int i = 0; i < 3; i++)
if (fork() == 0)
printf("%d ", i);
}- A. 3 numbers, sum 3
- B. 7 numbers, sum 7
- C. 8 numbers, sum 12
- D. 7 numbers, sum 10
Correct answer: D. 7 numbers, sum 10
At iteration i, 2^i processes fork and each new child prints i. So 1 child prints 0, 2 print 1, 4 print 2: 7 numbers with sum 0 + 2 + 8 = 10.
More Operating Systems questions
- Round Robin, quantum 2, processes (arrival, burst): A (0, 3), B (1, 5), C (2, 2), D (3, 4), E (4, 1). A process arriving exactly when a…
- Processes spend 60% of their time waiting for I/O, independently. Using CPU utilisation = 1 − pⁿ, what is the minimum degree of…
- How many of these statements about CPU scheduling are correct? 1. SJF minimises average waiting time among non-preemptive algorithms when…
- Three jobs of 10 ms each arrive at time 0. Compare the average turnaround time under FCFS and under Round Robin with a 1 ms quantum (no…
- Assertion (A): Shortest Remaining Time First is optimal for average waiting time when preemption is free. Reason (R): Running the job with…
- A multilevel queue scheduler has a foreground (interactive, RR) queue with absolute priority over a background (batch, FCFS) queue, and…