GATE GUIDE

Deadlock Questions in GATE CSE: Conditions, Formula, Banker's

By MD ANISH AHAMADUpdated 9 Oct 20269 min read
Deadlock Questions in GATE CSE: Conditions, Formula, Banker's

Deadlock is the Operating Systems topic where the whole mark turns on one arithmetic step. Either the minimum-units inequality is off by one or it is not, either the safety algorithm is run to the end or abandoned halfway. There is no long derivation and little interpretation. The method below covers every shape the paper has used, on one small table you can reuse.

In this guide
  1. Key takeaways
  2. Where deadlock sits in the paper
  3. The four conditions and what each strategy breaks
  4. The minimum-units formula
  5. Banker's algorithm and safe sequences
  6. Resource-allocation graphs and detection
  7. The traps in one list
  8. Exam technique
  9. How to practise

Key takeaways

Where deadlock sits in the paper

The 2027 syllabus names it in one word. Section 8 lists deadlock as its own sentence between synchronization and CPU scheduling, and that single word carries the four conditions, prevention, avoidance, detection and recovery.

Third-party analyst compilations put Operating Systems at 6 to 16 marks per paper across 2009 to 2026, averaging near 8.8. Split the series and 2009 to 2017 averages about 9.3 while 2018 to 2026 averages about 8.3, so the direction is slightly falling. The 16 in 2009 is not a trend, it reflects a 100-mark paper with no General Aptitude section. One analyst's count for the 2026 shift-2 paper put Operating Systems at five questions. Treat this as approximate and unofficial, since analysts differ by two or three marks on borderline questions. The cross-subject picture is in the guide to subject-wise weightage in GATE CSE.

Inside the subject, deadlock is a frequent item rather than a perennial one, appearing in roughly half the papers in some form. The ranking that places it against scheduling, paging and synchronization is in the Operating Systems important topics guide. Mark splits change every year, so check the current notification and the official question paper pattern.

The four conditions and what each strategy breaks

Deadlock needs all four of these simultaneously. Remove one permanently and deadlock cannot form.

Condition What it means Prevention strategy that breaks it
Mutual exclusion At least one resource is non-sharable Make resources sharable, for example spooling a printer. Rarely possible
Hold and wait A process holds one resource while requesting another Request all resources at once at the start, or release everything before requesting again
No preemption A resource cannot be forcibly taken back Preempt the held resources of a process whose new request cannot be granted
Circular wait A closed chain of processes each waiting on the next Impose a total order on resource types and allow requests only in increasing order

The common one-mark item is a statement mapping. Resource ordering breaks circular wait, not hold and wait. Requesting everything up front breaks hold and wait, not circular wait. Priority scheduling breaks nothing. Avoidance breaks none of the four: it lets them all remain possible and instead refuses requests that would leave an unsafe state.

The minimum-units formula

This is the highest-frequency deadlock calculation in the paper and it is almost always a numerical answer.

Take nn processes, one resource type, each needing at most kk units to finish. Build the worst state you can: give every process k−1k - 1 units, one short of its need. Nobody can finish, and that uses n(k−1)n(k - 1) units. Add one more unit and some process reaches kk, finishes, and releases everything it held, unblocking the rest.

So deadlock is impossible when the total mm satisfies

m≥n(k−1)+1,m \ge n(k - 1) + 1,

and the largest mm that still permits deadlock is n(k−1)n(k - 1).

Worked small case: 4 processes, each needing at most 3 units. Then n(k−1)=4×2=8n(k - 1) = 4 \times 2 = 8 units can still deadlock, with each process holding 2 and waiting for a third. With 9 units deadlock cannot occur. The same inequality answers the question asked backwards. Given m=11m = 11 and k=3k = 3, the largest nn that is still guaranteed deadlock-free satisfies:

n(k−1)+1≤112n≤10n=5\begin{aligned} n(k - 1) + 1 &\le 11 \\ 2n &\le 10 \\ n &= 5 \end{aligned}

The variant with unequal needs uses the same construction. Give each process needi−1\text{need}_i - 1 units, sum those, add one. If three processes need at most 3, 4 and 5 units, the threshold is 2+3+4+1=102 + 3 + 4 + 1 = 10. With 9 units a deadlock can still be arranged. With 10 it cannot. These are maximum needs, not current allocations, and the formula applies to a single resource type only.

Banker's algorithm and safe sequences

Avoidance requires every process to declare its maximum claim in advance. The state is then three matrices, and the first thing you compute is Need=Max−Allocation\text{Need} = \text{Max} - \text{Allocation}, element by element. Getting that wrong, or comparing a request against Max instead of Need, is the most expensive error in the topic.

Here is a three-process, two-resource state. Total units are A=6A = 6 and B=5B = 5.

Process Allocation (A, B) Max (A, B) Need (A, B)
P0 1, 1 3, 2 2, 1
P1 2, 1 4, 2 2, 1
P2 2, 2 3, 3 1, 1

Allocated totals are (5,4)(5, 4), so Available=(6,5)−(5,4)=(1,1)\text{Available} = (6, 5) - (5, 4) = (1, 1).

Now run the safety algorithm. Look for any process whose Need is componentwise at most Available. P0 and P1 both need (2,1)(2, 1) and fail on A. P2 needs (1,1)(1, 1) and passes. Assume P2 finishes and returns its allocation, so Available becomes (1,1)+(2,2)=(3,3)(1, 1) + (2, 2) = (3, 3).

Repeat. P0 needs (2,1)(2, 1), which fits, and returns (1,1)(1, 1), giving (3,3)+(1,1)=(4,4)(3, 3) + (1, 1) = (4, 4). P1 needs (2,1)(2, 1), which fits, and returns (2,1)(2, 1), giving (4,4)+(2,1)=(6,5)(4, 4) + (2, 1) = (6, 5). Every process is marked finished, so the state is safe and P2, P0, P1 is a safe sequence.

Count carefully when the question asks how many safe sequences exist. Only P2 can start. After it finishes, P0 and P1 can run in either order, so there are exactly two, not one. The usual error is to stop at the first sequence found.

Now the request half. Suppose P1 requests (1,0)(1, 0). Three checks run in order. Is Request≤Need\text{Request} \le \text{Need}? Yes. Is Request≤Available\text{Request} \le \text{Available}? Yes. Now pretend to grant it: P1's Allocation becomes (2,1)+(1,0)=(3,1)(2, 1) + (1, 0) = (3, 1), its Need becomes (2,1)−(1,0)=(1,1)(2, 1) - (1, 0) = (1, 1), and Available becomes (1,1)−(1,0)=(0,1)(1, 1) - (1, 0) = (0, 1). Re-run safety. P0 needs (2,1)(2, 1), P1 needs (1,1)(1, 1), P2 needs (1,1)(1, 1), and none fits inside (0,1)(0, 1). Nothing can start, so the pretend state is unsafe and the request is denied. P1 waits even though the units are physically sitting there.

One conceptual point is tested directly. A safe state is sufficient for deadlock freedom, not necessary. An unsafe state is not a deadlocked state. It only means the algorithm can no longer guarantee an ordering if every process claims its full maximum, and many unsafe states finish without trouble.

Resource-allocation graphs and detection

In a resource-allocation graph, a request edge runs from a process to a resource type and an assignment edge runs from a resource instance back to a process.

When every resource type has exactly one instance, a cycle is equivalent to deadlock, and finding the cycle is the whole answer. When at least one type has several instances, a cycle is necessary but not sufficient: a process on the cycle may be waiting on a type whose other instance is held by a process outside the cycle, and that process can finish and release it. For multiple instances, reduce the graph or run the detection algorithm.

Detection uses Allocation and Request matrices, where Request is the outstanding demand right now rather than a declared maximum. The procedure is the safety algorithm with Request in place of Need, and any process not marked finished at the end is deadlocked. A wait-for graph is the single-instance shortcut, obtained by collapsing each resource node so an edge runs straight from a waiting process to the holder.

Keep the four responses separate, because a one-mark statement question turns on exactly this. Prevention removes a condition by design. Avoidance uses declared maximums to refuse dangerous requests. Detection permits deadlock and finds it afterwards. Recovery clears it by preempting resources, rolling a process back to a checkpoint, or terminating processes until the cycle breaks.

The traps in one list

The cross-subject version of this list is in common mistakes that cost marks in GATE CSE, and the compact statements of both deadlock inequalities sit in the GATE CSE formula sheet.

Exam technique

Most deadlock items are numerical answer questions, which changes how you play them. A single off-by-one costs the entire mark, because there is no partial credit and no nearby option to check yourself against. Write the inequality in symbols first, then substitute once.

The other half of that fact is friendlier. There is no negative marking on numerical answer questions, so an attempted answer is free. If a deadlock numerical is the last thing left and the matrices are half-solved, enter your best figure rather than leaving it blank. The rules for deciding this across question types are in the guide to MSQ, NAT and MCQ strategy, and the marking scheme is set afresh each year, so confirm it in the current notification.

How to practise

Reuse one three-process, two-resource table. Change a number in Allocation and re-run safety. Change a number in Max and watch a safe state turn unsafe. Ask how many safe sequences exist each time, not just whether one exists.

For the formula, drill both directions: given nn and kk find mm, given mm and kk find the largest nn, then repeat with unequal needs. The Operating Systems chapter of the GATE CSE 2027 book carries a full deadlock question bank with worked safety runs, safe-sequence counts and request-grant decisions, solved step by step.

Frequently asked questions

What is the minimum number of resource units so that deadlock cannot occur?

For nn processes that each need at most kk units of one resource type, deadlock becomes impossible once the total number of units is at least nn times kk minus 1, plus 1. Written out, the threshold is n(k−1)+1n(k - 1) + 1. The largest total that still permits deadlock is n(k−1)n(k - 1), where every process holds k−1k - 1 units and waits forever for one more.

How do you compute the answer when processes have different maximum needs?

Add up needi−1\text{need}_i - 1 over all processes, then add 1, giving ∑i(needi−1)+1\sum_i (\text{need}_i - 1) + 1. That total is the smallest number of units for which deadlock is impossible. The reasoning is the same as the equal-needs case. The worst distribution gives every process one unit short of its maximum, and a single extra unit lets at least one process finish and release everything it holds.

Does a cycle in a resource-allocation graph always mean deadlock?

Only when every resource type has exactly one instance. In that case a cycle and a deadlock are the same thing. When a resource type has several instances, a cycle is necessary but not sufficient, because a process outside the cycle may hold an instance and release it later. For multiple instances you must run the detection algorithm instead of reading the picture.

Is an unsafe state the same as a deadlocked state?

No. Safety is sufficient for deadlock freedom but not necessary. A safe state guarantees that some ordering lets every process finish. An unsafe state only means the Banker's algorithm cannot prove that, so deadlock is possible if processes actually claim their stated maximums. Many unsafe states never deadlock in practice, which is why avoidance is considered conservative.

What is the difference between deadlock prevention, avoidance and detection?

Prevention designs the system so one of the four necessary conditions can never hold. Avoidance allows all four but refuses any request that would leave an unsafe state, which needs the maximum claims in advance. Detection allows deadlock to happen, then runs an algorithm on the allocation and request matrices and recovers by preemption, rollback or termination.

Sources

Dates, fees and the syllabus are set by the GATE 2027 organising institute and can change. Always confirm at gate2027.iitm.ac.in.

Keep reading

GATE CSE 2027 book1,020 pages · ₹250 ₹300
Buy now — ₹250