Deadlocks MCQs for NSCT

By the NSCT Exam Editorial Team · Updated 2026-11-24 · Facts checked against official sources on 2026-11-24

A deadlock is a state in which a set of processes are all blocked, each waiting for a resource held by another process in the same set, so none of them can ever continue. It is topic 7 of the Operating Systems area, which carries 5% of the NSCT according to HEC's Areas of Competencies. OS was the lowest-scoring area in 2026, with candidates averaging 33.8% accuracy, per the HEC NSCT report and APP.

Deadlock builds on concurrency and synchronisation: two mutex locks taken in opposite orders are the classic way to cause one. This page follows Silberschatz's Operating System Concepts.

Coffman conditions

Deadlock can happen only if all four of these conditions hold at the same time (the Coffman conditions):

Condition Meaning Broken by
Mutual exclusion At least one resource is non-sharable Making resources sharable (rarely possible)
Hold and wait A process holds resources while waiting for more Requesting everything up front, or only when holding nothing
No pre-emption Resources cannot be taken away Letting the OS pre-empt resources from waiting processes
Circular wait P0 waits for P1, …, Pn waits for P0 Numbering resources and requesting them in increasing order

A resource-allocation graph (RAG) shows processes, resources, request edges (P → R) and assignment edges (R → P). If every resource has one instance, a cycle means deadlock. With several instances, a cycle is necessary but not sufficient: a process outside the cycle may release an instance and break it.

Exam angle: "a cycle always means deadlock" is true only for single-instance resources. This is the trap most often set on RAG questions.

Banker's algorithm

Deadlock avoidance lets the OS grant a request only if the system stays in a safe state, one where some order exists in which every process can get its maximum claim and finish. The Banker's algorithm uses four structures for n processes and m resource types:

The safety algorithm sets Work = Available, then repeatedly finds an unfinished process with Need ≤ Work, pretends it finishes, and adds its Allocation to Work. If all processes finish, the state is safe. It costs O(m × n²).

Example with Available (3, 1, 1):

Process Allocation Max Need
P0 1 0 2 4 3 3 3 3 1
P1 2 1 0 3 2 2 1 1 2
P2 0 2 1 5 2 4 5 0 3
P3 1 1 1 2 2 2 1 1 1
P4 0 0 2 3 3 3 3 3 1

If you always pick the lowest-numbered process that fits, you get P3 → (4,2,2), P1 → (6,3,2), P0 → (7,3,4), P2 → (7,5,5), P4 → (7,5,7). The state is safe, with the sequence P3, P1, P0, P2, P4.

Exam angle: safe sequences are often not unique, so check every option rather than looking for "the" sequence. An unsafe state is not yet a deadlock; it only means the OS can no longer guarantee that every process finishes. The Banker's algorithm page has more worked numericals.

Prevention, detection and recovery

Prevention makes one Coffman condition impossible by design. Requesting all resources at the start denies hold and wait, but wastes resources and can starve processes. Total resource ordering denies circular wait, and it is the method most used in practice for locks.

Detection lets deadlocks happen and then finds them. For single-instance resources, look for a cycle in the wait-for graph (the RAG with resource nodes removed). For several instances, run a Banker-like algorithm using each process's current Request instead of Need.

Recovery either aborts processes (all of them, or one at a time until the cycle breaks) or pre-empts resources. Pre-emption raises three issues: picking a victim, rolling it back, and avoiding starvation, usually by counting rollbacks in the victim's cost.

Silberschatz notes that most operating systems, including Linux and Windows, simply ignore deadlocks in application code (the "ostrich" approach) and leave it to developers.

Strategy When it acts Cost
Prevention Design time Low utilisation
Avoidance (Banker's) Each request Needs Max in advance, O(m × n²) per check
Detection and recovery After deadlock Lost work when processes are aborted

Exam angle: for n processes that each need at most k units of one resource, deadlock is impossible when the total is at least n(k − 1) + 1.

Common traps

Worked examples

Understanding. A policy lets the OS take resources away from a process that is waiting for something else. Which condition does it remove? Answer: no pre-emption. If held resources can be pre-empted, a waiting process cannot block others indefinitely. This works for resources whose state can be saved, such as CPU registers and memory, but not for printers or mutex locks.

Application. Four processes share a resource, and each needs at most 3 units. What is the fewest units that rules out deadlock? Answer: 9. In the worst case each process holds 2 units (8 in total) and waits for a third. One more unit lets a process finish and release its units, so 4 × 2 + 1 = 9.

Analysis. The state has Available (1, 1). Allocation is P0 (1, 0), P1 (1, 1), P2 (0, 1), and Max is P0 (3, 2), P1 (2, 2), P2 (2, 3). P2 requests (0, 1). Should it be granted? Answer: no, P2 must wait. The current state is safe: Need is P0 (2,2), P1 (1,1), P2 (2,2), and the sequence P1, P0, P2 works. Granting the request leaves Available at (1, 0), so P1's Need (1, 1) no longer fits, and neither does anyone else's. That state is unsafe, so the Banker's algorithm makes P2 wait.

Practise

The quiz below has 100 Deadlocks questions, which you can filter by tier and difficulty.

Practise: 100 questions

Interactive quiz loading. The first 10 questions are shown below.

  1. Which of these is NOT one of the four necessary (Coffman) conditions for deadlock?

    1. Hold and wait
    2. Starvation
    3. No pre-emption
    4. Circular wait
    Show answer

    Answer: B. Starvation

    The four conditions are mutual exclusion, hold and wait, no pre-emption and circular wait. Starvation (a process waiting indefinitely while others progress) is a different problem; it can happen without any deadlock.

  2. The mutual exclusion condition for deadlock means that:

    1. Every process must lock a mutex before entering its critical section
    2. Processes must request all their resources at once
    3. A resource can be taken away from a process only by the OS
    4. At least one resource is non-sharable, so only one process can use it at a time
    Show answer

    Answer: D. At least one resource is non-sharable, so only one process can use it at a time

    Mutual exclusion as a deadlock condition says at least one resource is held in non-sharable mode, such as a printer or a write lock. If every resource were sharable (like read-only files), no process would ever wait for one.

  3. Processes P0, P1 and P2 are such that P0 waits for a resource held by P1, P1 waits for one held by P2, and P2 waits for one held by P0. Which deadlock condition does this chain describe?

    1. Circular wait
    2. Hold and wait
    3. Mutual exclusion
    4. No pre-emption
    Show answer

    Answer: A. Circular wait

    A closed chain of processes, each waiting for a resource held by the next, is circular wait. Hold and wait is about a single process holding something while asking for more; it is implied here but is not what the chain itself shows.

  4. In a resource-allocation graph where every resource type has exactly one instance, a cycle means:

    1. A deadlock may exist, but further analysis is needed
    2. The system is in an unsafe state but not yet deadlocked
    3. Only the process with the most resources is deadlocked
    4. A deadlock exists, and every process on the cycle is deadlocked
    Show answer

    Answer: D. A deadlock exists, and every process on the cycle is deadlocked

    With single-instance resources, a cycle is both necessary and sufficient for deadlock (Silberschatz). Each process on the cycle waits for the one unit held by the next, so none can ever proceed.

  5. When resource types have several instances each, a cycle in the resource-allocation graph is:

    1. Sufficient but not necessary for deadlock
    2. Both necessary and sufficient for deadlock
    3. Neither necessary nor sufficient for deadlock
    4. Necessary but not sufficient for deadlock
    Show answer

    Answer: D. Necessary but not sufficient for deadlock

    Without a cycle there can be no deadlock, so a cycle is necessary. But with multiple instances, a process outside the cycle may release an instance and break the wait, so a cycle alone does not prove deadlock.

  6. Numbering all resource types and forcing every process to request them in increasing order prevents deadlock by breaking which condition?

    1. Hold and wait
    2. Mutual exclusion
    3. Circular wait
    4. No pre-emption
    Show answer

    Answer: C. Circular wait

    If requests always go up the numbering, a cycle would need some process to hold a higher-numbered resource while waiting for a lower one, which the rule forbids. So circular wait can never form.

  7. A protocol makes each process request and be allocated all its resources before it starts running. Which deadlock condition does this deny?

    1. Circular wait
    2. Mutual exclusion
    3. Hold and wait
    4. No pre-emption
    Show answer

    Answer: C. Hold and wait

    A process that gets everything up front never holds one resource while waiting for another, so hold and wait cannot occur. The cost is poor resource utilisation and possible starvation of processes needing many popular resources.

  8. Which statement about safe and unsafe states (in the Banker's algorithm sense) is correct?

    1. An unsafe state is always a deadlocked state
    2. An unsafe state may lead to deadlock, but is not itself a deadlock
    3. A safe state can still lead to deadlock if processes request their maximum
    4. Safe and unsafe states are only defined for single-instance resources
    Show answer

    Answer: B. An unsafe state may lead to deadlock, but is not itself a deadlock

    Silberschatz: a deadlocked state is unsafe, but not every unsafe state is deadlocked. Unsafe means the OS can no longer guarantee that every process will finish; whether deadlock actually happens depends on the future requests.

  9. The Banker's algorithm is an example of which deadlock-handling strategy?

    1. Deadlock avoidance
    2. Deadlock prevention
    3. Deadlock detection and recovery
    4. Ignoring deadlock (ostrich approach)
    Show answer

    Answer: A. Deadlock avoidance

    The Banker's algorithm checks each request against the processes' declared maximum claims and grants it only if the system stays in a safe state. Deciding dynamically like this is avoidance; prevention instead rules out one of the four conditions by design.

  10. In the Banker's algorithm, how is the Need matrix calculated?

    1. Need = Allocation − Max
    2. Need = Available − Allocation
    3. Need = Max − Available
    4. Need = Max − Allocation
    Show answer

    Answer: D. Need = Max − Allocation

    Need[i][j] is how many more instances of resource j process i may still request: its declared maximum minus what it already holds. It is the value compared against Work in the safety algorithm.

FAQs

What is the difference between deadlock prevention and avoidance?

Prevention makes deadlock impossible by design: it rules out one of the four conditions for every request, for example through resource ordering. Avoidance allows all four conditions but checks each request at run time, granting it only if the system stays in a safe state. Avoidance uses resources better but needs each process's maximum claim in advance.

Does a safe state guarantee there will be no deadlock?

Yes, as long as the OS keeps using the avoidance check. From a safe state there is at least one order in which every process can get its maximum and finish. The Banker's algorithm only grants requests that keep the system safe, so it never enters a state from which deadlock is possible.

Can deadlock happen with only one process?

Not in the usual sense, because the definition needs a set of processes waiting on each other. However, a single thread can block itself forever, for example by trying to lock a non-recursive mutex it already holds. Some texts call this self-deadlock. It is a programming bug, not a Coffman-style cycle between processes.

Is livelock the same as deadlock?

No. In livelock, processes are not blocked: they keep running and changing state, but they make no progress. An example is two threads that each back off and retry at the same moment, forever. Deadlocked processes are blocked and do nothing. Random back-off times usually fix livelock.

Next step

Continue with Memory Management MCQs, go back to the Operating Systems hub, or try a timed NSCT mock test.