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
Key takeaways
- All four conditions must hold at once. Prevention permanently removes exactly one.
- For processes each needing at most units of a single resource type, deadlock is impossible when the total is at least . The largest total that still permits deadlock is .
- With unequal maximum needs, sum over all processes and add 1.
- . Safe implies deadlock-free, but unsafe does not imply deadlock.
- One instance per type makes a cycle equivalent to deadlock. Multiple instances make a cycle necessary but not sufficient.
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 processes, one resource type, each needing at most units to finish. Build the worst state you can: give every process units, one short of its need. Nobody can finish, and that uses units. Add one more unit and some process reaches , finishes, and releases everything it held, unblocking the rest.
So deadlock is impossible when the total satisfies
and the largest that still permits deadlock is .
Worked small case: 4 processes, each needing at most 3 units. Then 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 and , the largest that is still guaranteed deadlock-free satisfies:
The variant with unequal needs uses the same construction. Give each process units, sum those, add one. If three processes need at most 3, 4 and 5 units, the threshold is . 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 , 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 and .
| 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 , so .
Now run the safety algorithm. Look for any process whose Need is componentwise at most Available. P0 and P1 both need and fail on A. P2 needs and passes. Assume P2 finishes and returns its allocation, so Available becomes .
Repeat. P0 needs , which fits, and returns , giving . P1 needs , which fits, and returns , giving . 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 . Three checks run in order. Is ? Yes. Is ? Yes. Now pretend to grant it: P1's Allocation becomes , its Need becomes , and Available becomes . Re-run safety. P0 needs , P1 needs , P2 needs , and none fits inside . 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
- Off-by-one in the formula. still deadlocks, does not.
- Using current allocation instead of declared maximum need.
- Computing Need as Max rather than .
- Checking a request against Available but not Need, or the reverse.
- Reporting one safe sequence when the question asks how many exist.
- Treating an unsafe state as a deadlocked state.
- Reading a cycle as deadlock when a type has multiple instances.
- Matching a prevention strategy to the wrong condition.
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 and find , given and find the largest , 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 processes that each need at most units of one resource type, deadlock becomes impossible once the total number of units is at least times minus 1, plus 1. Written out, the threshold is . The largest total that still permits deadlock is , where every process holds units and waits forever for one more.
How do you compute the answer when processes have different maximum needs?
Add up over all processes, then add 1, giving . 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
- GATE 2027 official website (IIT Madras)
- GATE 2027 CS syllabus (official PDF)
- GATE 2027 question paper pattern (official)
- GeeksforGeeks subject-wise weightage for GATE CS
- GATE Overflow previous year questions
Dates, fees and the syllabus are set by the GATE 2027 organising institute and can change. Always confirm at gate2027.iitm.ac.in.