CS FundamentalsVery hardProduct company interview · GATE level

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 (2,2,1,1), P3 (1,2,3,2), P4 (3,1,2,1); Available (1,1,1,1). Considered separately, can the banker's algorithm immediately grant (i) P4's request (1,0,0,0) and (ii) P1's request (0,0,1,0)?

  1. A. Neither can be granted
  2. B. Only P4's request can be granted
  3. C. Both can be granted
  4. D. Only P1's request can be granted

Correct answer: D. Only P1's request can be granted

Both requests are within the requester's need and within Available, so the safety test decides. (i) Granting P4 leaves Available (0,1,1,1). Every process then needs at least one A (P0 3, P2 1, P3 1, P4 1) except P1, which needs 2 of D - nobody can finish, so the state is unsafe and P4 must wait. (ii) Granting P1 leaves (1,1,0,1). P2 needs (1,1,0,1) and can finish, releasing to (2,2,1,1); then P3 or P4 can run, and so on to a complete safe sequence. A request that fits in Available is not automatically safe.

More Operating Systems questions

Exams that ask this topic