CS FundamentalsVery hardProduct company interview · GATE level
Semaphores a = 0 and b = 0. Three processes run concurrently: P: print('A'); signal(a); wait(b); print('B'); Q: wait(a); print('C'); signal(b); signal(a); R: wait(a); print('D'); signal(b); Which statement is correct?
- A. ACBD, ACDB and ADCB are all possible complete outputs
- B. The only complete outputs are ACBD and ACDB, and deadlock is impossible
- C. The only complete outputs are ACBD and ACDB, and the system can also deadlock after printing ADB
- D. The output is always ACBD
Correct answer: C. The only complete outputs are ACBD and ACDB, and the system can also deadlock after printing ADB
After A, the single signal(a) wakes either Q or R. If Q wins, it prints C, signals b and passes a on to R; P (waiting on b) and R then race, giving ACBD or ACDB. If R wins, it prints D and signals b, so P prints B, but nobody ever signals a again: Q waits forever after the output ADB. ADCB is impossible because C requires a, which only Q itself would re-signal.
More Operating Systems questions
- Two processes (i = 0, 1; j = 1 - i) share bool flag[2] = {false, false} and int turn, and each runs entry code, then its critical section…
- How many lines print the value 3, and what is the sum of all the values printed? (Assume every fork() succeeds.) c int main() { int c = 0…
- A buddy allocator manages 1024 KB and splits blocks in powers of two, always using the lowest-addressed free block of the needed size…
- A disk has cylinders 0-499. The head is at 237 and is moving towards cylinder 0. Pending requests: 312, 45, 401, 198, 260, 12, 477, 150…
- A disk spins at 12,000 RPM, has 250 sectors of 512 bytes per track, an average seek time of 4 ms and a track-to-track seek time of 0.5 ms…
- A machine has 40-bit virtual addresses, 16 KB pages and 4-byte page-table entries. Every page table at every level must fit in a single…