CS FundamentalsVery hardProduct company interview · GATE level
Five processes P0-P4 share four resource types A, B, C, D. Allocation: P0 (0,1,0,1), P1 (2,0,0,1), P2 (1,1,1,0), P3 (0,0,2,1), P4 (1,0,1,0). Max: P0 (3,2,2,2), P1 (2,1,1,3), P2 (2,2,1,1), P3 (1,2,3,2), P4 (3,1,2,1). Available: (1,1,1,1). How many distinct safe sequences exist?
- A. 4
- B. 1
- C. 8
- D. 12
Correct answer: C. 8
Need = Max - Allocation: P0 (3,1,2,1), P1 (0,1,1,2), P2 (1,1,0,1), P3 (1,2,1,1), P4 (2,1,1,1). With (1,1,1,1) only P2 fits, so every safe sequence starts with P2, giving (2,2,2,1). Now P3 or P4 fits but P1 (needs 2 of D) does not; P0 needs 3 of A. After P2, P3 the pool is (2,2,4,2): P1 and P4 can run, and P0 can run once either has finished, giving 4 orders (P2 P3 P1 P0 P4, P2 P3 P1 P4 P0, P2 P3 P4 P0 P1, P2 P3 P4 P1 P0). After P2, P4 the pool is (3,2,3,1): P0 and P3 can run, and P1 only after P3, giving another 4. Total 8 safe sequences. The state is safe, but answering 1 confuses 'safe' with 'has a unique safe order'.
More Operating Systems questions
- Use the same state: Allocation P0 (0,1,0,1), P1 (2,0,0,1), P2 (1,1,1,0), P3 (0,0,2,1), P4 (1,0,1,0); Max P0 (3,2,2,2), P1 (2,1,1,3), P2…
- A system with resource types A, B, C (several instances each) runs the deadlock-detection algorithm. Allocation: P0 (0,1,0), P1 (2,0,0)…
- Shared int x = 1. Thread T1 executes x = x + 1; twice; thread T2 executes x = x 2; once. Each statement compiles to a load of x into a…
- Semaphores a = 0 and b = 0. Three processes run concurrently: P: print('A'); signal(a); wait(b); print('B'); Q: wait(a); print('C')…
- 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…