CS FundamentalsVery hardGATE CS
How many processes are created in total, including the original? (Every fork() succeeds.)
How many processes are created in total, including the original? (Every fork() succeeds.)
int main() {
for (int i = 0; i < 3; i++)
if (fork() && fork())
break;
printf("x\n");
}- A. 15
- B. 8
- C. 27
- D. 9
Correct answer: A. 15
In each iteration a looping process creates two children: the first child (fork() == 0) and the second child (second fork() == 0) both continue looping, while the original breaks. So the number of looping processes doubles each round: 1 → 2 → 4 → 8 continue past i = 2. Total processes = 1 + 2 + 4 + 8 = 15.
More Operating Systems questions
- Processes (arrival, burst): P1 (0, 7), P2 (2, 3), P3 (3, 1), P4 (6, 2). SRTF is used and every switch to a DIFFERENT process costs 1 ms…
- Processes on one CPU, Round Robin quantum 2: A arrives at 0 and needs CPU 3, then I/O 2, then CPU 1; B arrives at 1 and needs CPU 4. A…
- Processes (arrival, burst): P1 (0, 2), P2 (1, 9), P3 (2, 1), P4 (3, 1), P5 (4, 1). Rank FCFS, non-preemptive SJF, SRTF and RR (q = 1) by…
- Reference string: 1, 2, 3, 4, 5, 3, 4, 1, 6, 7, 8, 7, 8, 9, 7, 8, 9, 5, 4, 5, 4, 2. With 4 frames (initially empty), how many page faults…
- Under which condition does the clock (second-chance) algorithm make exactly the same replacement decisions as FIFO?
- A two-level page table, TLB lookup 10 ns, memory 80 ns, TLB hit ratio 90%. On a TLB miss, a page-walk cache holding outer-level entries…