CS FundamentalsVery hardAmazon · Microsoft MCQ pattern
Consider this loop:
Consider this loop:
for (int i = 0; i < 2; i++) {
fork();
printf("-");
}stdout is redirected to a file (fully buffered) and no fflush is called. How many dashes appear in the file?- A. 4
- B. 8
- C. 3
- D. 6
Correct answer: B. 8
6 printf calls run in total, but the buffer is copied by fork. At i = 1, the 2 processes each hold "-" unflushed and fork, so all 4 final processes hold "--" and flush at exit: 4 × 2 = 8. With line-buffered output and a newline it would be 6.
More Operating Systems questions
- Which CPU scheduling algorithm can make a long process wait indefinitely if short processes keep arriving?
- Which part of the operating system selects which process in the ready queue gets the CPU next?
- Processes (arrival, burst): P1 (0, 4), P2 (1, 3), P3 (2, 6), P4 (4, 2). What is the average turnaround time under FCFS?
- Reference string: 1, 3, 0, 3, 5, 6, 3, 1, 0, 6, 5, 3. With 3 frames, initially empty, how many page faults does FIFO replacement cause?
- Pure paging (fixed-size pages and frames) can suffer from which kind of fragmentation?
- The Banker’s algorithm is used for which strategy of handling deadlocks?