CS FundamentalsHardAmazon · Microsoft MCQ pattern
Semaphores S = 1 and T = 0. Process X runs: wait(S); print('A'); signal(T); Process Y runs: wait(T); print('B'); signal(S); Each runs its code in an infinite loop. Which output prefix is possible?
- A. ABBA…
- B. AABB…
- C. ABAB…
- D. BABA…
Correct answer: C. ABAB…
Y cannot print until X signals T, and X cannot print again until Y signals S, so prints strictly alternate starting with A: ABAB… Any other pattern needs two consecutive prints by the same process, which the semaphores forbid.
More Operating Systems questions
- Two threads each run the loop for (i = 0; i < 5; i++) count++; on a shared int count = 0, with no synchronisation. count++ is compiled to…
- How many times is "x" printed? (fork() returns 0 in the child and a positive PID in the parent; assume it always succeeds.) c int main() {…
- How many times is "x" printed? (Assume every fork() succeeds.) c int main() { fork(); fork() || fork(); printf("xn"); return 0; }
- 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…