GATE / CS ARCHIVE

SIMILAR QUESTIONS / OPERATING SYSTEMS

Reduce resource snapshots to test safety

3 questions solved the same way, newest first. Back to Operating Systems

How these are solved

Use the supplied allocation and remaining-need/request vectors and available resources to find a satisfiable process, release its allocation and repeat. Preserve whether a table states maxima or remaining requests.

2 marks · MCQ
Report issue

A Banker safety sequence

Deadlocks

Question 39, GATE 2018: Available (E,F,G)=(3,3,0). Allocation rows P0…P3 are (1,0,1),(1,1,2),(1,0,3),(2,0,0); Max rows are (4,3,1),(2,1,4),(1,3,3),(5,4,1). Choose A safe already; B unsafe but safe with one extra E; C likewise extra F; D likewise extra G.
Tap to enlarge
Your answer
Answer & solution

Official answer: A

Step through it (6 steps)

Method

Banker’s safety test asks whether there exists an order in which each process can obtain all its remaining need and release its allocation. Need=Max−Allocation, computed component by component. After hypothetically finishing a process, Work increases by its original Allocation, not by its Max: any temporary extra resources lent from Work are returned, cancelling out. Initially P0 and P2 are both eligible. Exhibiting one complete order suffices; the algorithm need not show that every arbitrary request order is safe.

Solution

Subtract Allocation from Max to obtain remaining needs P0=(3, 3, 0), P1=(1, 0, 2), P2=(0, 3, 0), P3=(3, 4, 1). Starting Work=(3, 3, 0), complete P0 to get(4, 3, 1), then P2 to get(5, 3, 4), then P1 to get(6, 4, 6), then P3. This safe sequence proves A.

Original paper, page 16 · Answer key

2 marks · MCQ
Report issue

Safe completion order from available resources

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

Descriptive
Report issue

Safety of the Banker state

Deadlocks

Question 22(a), GATE 1996: Three processes P0,P1,P2 share resource types R0,R1,R2. Maximum total claims are P0=(4,1,2), P1=(1,5,1), P2=(1,2,3). Current allocations are P0=(1,0,2), P1=(0,3,1), P2=(1,0,2), and Available=(2,2,0). Show that this can be a state admitted by the Banker’s algorithm.
Question 22(a), GATE 1996: Three processes P0,P1,P2 share resource types R0,R1,R2. Maximum total claims are P0=(4,1,2), P1=(1,5,1), P2=(1,2,3). Current allocations are P0=(1,0,2), P1=(0,3,1), P2=(1,0,2), and Available=(2,2,0). Show that this can be a state admitted by the Banker’s algorithm.
Tap to enlarge
Answer & solution

Answer: Safe sequence P1→P2→P0; Work evolves (2,2,0)→(2,5,1)→(3,5,3)→(4,5,5). (no official key was published)

Step through it (5 steps)

The table heading “Maximum Need” gives total claims, not outstanding requests. Subtract each allocation to obtain remaining Need: P0=(3,1,0), P1=(1,2,0), P2=(0,2,1). The total resource vector is Available plus all allocations, namely (4,5,5); every maximum is individually within this total.

Run the safety test with Work=(2,2,0). P0 cannot finish yet because it needs 3 units of R0 but only 2 are free. P2 cannot finish because it needs one R2 while none is free. P1 can finish since (1,2,0) is componentwise at most (2,2,0). After it finishes, Work increases by its current allocation (0,3,1), yielding (2,5,1). Adding allocation, rather than maximum, is correct: its extra temporary requests are returned too, leaving the net increase equal to the allocation it already held.

Now P2's need (0,2,1) fits, so its completion releases (1,0,2) and Work becomes (3,5,3). Finally P0's need (3,1,0) fits; releasing (1,0,2) yields (4,5,5). Thus P1,P2,P0 is a safe sequence, proving that all claims can be satisfied in a suitable order. Safety does not assert that every possible future request is immediately grantable; it establishes at least one completion schedule from the current allocations.

Original paper, page 10