CS FundamentalsHardProduct-company MCQ pattern
How many times is "x" printed? (Assume every fork() succeeds.)
How many times is "x" printed? (Assume every fork() succeeds.)
int main() {
fork();
fork() || fork();
printf("x\n");
return 0;
}- A. 8
- B. 6
- C. 3
- D. 2
Correct answer: B. 6
After the first fork there are 2 processes. In each, the parent of `fork() || fork()` gets a non-zero value and short-circuits; only the child forks again, so each process becomes 3: 2 × 3 = 6. Ignoring the short-circuit gives 2³ = 8, forgetting the first fork gives 3, and 2 counts only the first fork.
More Operating Systems questions
- How many lines are printed in total? (Assume every fork() succeeds.) c int main() { for (int i = 0; i < 3; i++) { if (fork() == 0)…
- A 64-bit machine uses 48-bit virtual addresses, 4 KB pages and 8-byte page-table entries. Every page table occupies exactly one page. How…
- A system uses two-level paging and a TLB. TLB access = 10 ns, memory access = 100 ns, TLB hit ratio = 90%. The TLB is searched first, and…
- TLB access = 20 ns, memory access = 100 ns, single-level page table, TLB searched first. What is the minimum TLB hit ratio for the…
- Memory access takes 100 ns and a page fault takes 5 ms to service. For the effective access time to be at most 20% slower than a…
- A machine has 1 GB of physical memory, 4 KB pages, 64-bit virtual addresses and an inverted page table. How many entries does the inverted…