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?

  1. A. 4
  2. B. 1
  3. C. 8
  4. 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

Exams that ask this topic