CS FundamentalsHardGATE CS · Amazon/Microsoft SDE MCQ
How many times is x printed? (Every fork() succeeds, and each print is an unbuffered write.)
How many times is x printed? (Every fork() succeeds, and each print is an unbuffered write.)
int main() {
fork();
fork() && fork();
fork();
printf("x");
}- A. 8
- B. 16
- C. 12
- D. 10
Correct answer: C. 12
The first fork gives 2 processes. In fork() && fork(), each process's parent side continues to the second fork while the child side short-circuits, so each process becomes 3. The final fork doubles: 2 × 3 × 2 = 12.
More Operating Systems questions
- How many numbers are printed, and what is their sum? (Every fork() succeeds, and each print is an unbuffered write.) c int main() { for…
- Which letters are printed, and how many times each? (Every fork() succeeds, and each print is an unbuffered write.) c int main() { if…
- Periodic tasks T1 (execution 2, period 5) and T2 (execution 4, period 7), deadlines equal to periods. Which statement is correct?
- Each process spends 50% of its time waiting for I/O, independently of the others. Under the simple model CPU utilisation = 1 − pⁿ, what is…
- Memory access takes 100 ns. A page fault occurs once per million accesses; servicing it takes 8 ms if the victim page is clean and 20 ms…
- An inode has 12 direct pointers, one single-indirect and one double-indirect pointer; blocks are 4 KB and pointers 8 bytes. What is the…