GATE / CS ARCHIVE

GATE CSE 2007 / QUESTION 57

Safe completion order from available resources

Operating Systems · Deadlocks · Full GATE CSE 2007 paper

GATE 2007, Q57 2 marks · MCQ
Report issue

Deadlocks

Question 57, GATE 2007: Three processes share resource types X,Y,Z, with 5 units of each. Allocated and additionally requested vectors (X,Y,Z) are: P0 alloc=(1,2,1), request=(1,0,3); P1 alloc=(2,0,1), request=(0,1,2); P2 alloc=(2,2,1), request=(1,2,0). Each request is needed to finish, after which resources are released. Which process finishes last?
Options:
(A) P0
(B) P1
(C) P2
(D) None; the system is deadlocked
Tap to enlarge
Your answer
Answer & solution

Answer: C (no official key was published)

Step through it (5 steps)

1. Approach. Subtract all allocations from the total vector to obtain current availability. Repeatedly choose a process whose remaining request fits componentwise, then add its old allocation back to availability.

2. Derivation and interpretation. Allocated totals are (1,2,1)+(2,0,1)+(2,2,1)=(5,4,3), so the initial available vector is (0,1,2). Only P1's remaining request (0,1,2) can be met. After P1 completes and returns all its resources, availability becomes (0,1,2)+(2,0,1)=(2,1,3). P0's request (1,0,3) can now be met, while P2 still needs two Y units but only one is available. P0 finishes next, leaving availability (2,1,3)+(1,2,1)=(3,3,4), which permits P2's request (1,2,0). The forced safe order is P1,P0,P2, so P2 finishes last (C), assuming each request is the additional resource vector needed for completion as stated.

Original paper, page 14