HomeSubjectsUniversityBlogAbout

Deadlocks

Topic in Operating Systems

210 total MCQsShowing 30 with explanations10 Easy10 Medium10 Hard

About This Topic

A deadlock is a state in which a set of processes wait forever because each one holds a resource that another process in the set is waiting for. Almost every question builds on the four Coffman conditions: mutual exclusion, hold and wait, no preemption and circular wait. You should be able to read a resource-allocation graph, explain why a cycle guarantees deadlock only when every resource has a single instance, and run the Banker's algorithm to decide whether a state is safe. Other material covers prevention by breaking a condition, such as ordering resource types, the wait-for graph for detection, recovery through process termination or preemption, victim selection, and livelock.

Below are 30 practice questions from a pool of 210 Deadlocks MCQs, one of 12 topics in Operating Systems. Each shows the correct answer with an explanation; when you are ready, take a timed quiz to test recall under exam conditions.

Practice Questions

Each question below shows the correct answer with a full explanation. Use these to build conceptual understanding before attempting a timed quiz.

DeadlocksEasy

Q1. A deadlock occurs when:

  1. A.Processes wait indefinitely for resources held by each other✓ Correct
  2. B.A process enters an infinite loop consuming all CPU time
  3. C.The CPU is overloaded with too many running processes
  4. D.A process terminates unexpectedly due to an error

Explanation

A deadlock is a situation where two or more processes are each waiting for a resource held by another process in the set, creating a circular wait where none can proceed.

Report an error in this question

DeadlocksEasy

Q2. How many necessary conditions must hold simultaneously for a deadlock to occur?

  1. A.Three
  2. B.Four✓ Correct
  3. C.Two
  4. D.Five

Explanation

Four conditions must hold simultaneously: mutual exclusion, hold and wait, no preemption, and circular wait. These are known as the Coffman conditions.

Report an error in this question

DeadlocksEasy

Q3. Which of the following is NOT a necessary condition for deadlock?

  1. A.Mutual exclusion
  2. B.Hold and wait
  3. C.Circular wait
  4. D.Preemption✓ Correct

Explanation

The four necessary conditions are: mutual exclusion, hold and wait, NO preemption (not preemption), and circular wait. Preemption would actually help prevent deadlock.

Report an error in this question

DeadlocksEasy

Q4. The 'hold and wait' condition means:

  1. A.A process waits without holding any resource
  2. B.A process holds no resources at all currently
  3. C.A process releases all resources before waiting
  4. D.A process holds resources while waiting for more✓ Correct

Explanation

Hold and wait means a process is holding at least one resource and is waiting to acquire additional resources that are currently being held by other processes.

Report an error in this question

DeadlocksEasy

Q5. Circular wait means:

  1. A.Processes are scheduled in a circular fashion
  2. B.Each process waits for the next, forming a cycle✓ Correct
  3. C.Processes simply wait in a standard queue
  4. D.Only one single process is actively waiting

Explanation

Circular wait exists when there is a chain of processes P0, P1, ..., Pn where P0 waits for a resource held by P1, P1 waits for P2, and so on, with Pn waiting for P0.

Report an error in this question

DeadlocksEasy

Q6. Deadlock prevention works by:

  1. A.Ignoring deadlocks entirely and hoping they pass
  2. B.Ensuring at least one necessary condition fails✓ Correct
  3. C.Recovering from deadlocks by terminating tasks
  4. D.Detecting deadlocks after they already occurred

Explanation

Deadlock prevention ensures that at least one of the four necessary conditions (mutual exclusion, hold and wait, no preemption, circular wait) cannot hold, making deadlock structurally impossible.

Report an error in this question

DeadlocksEasy

Q7. A resource allocation graph is used to:

  1. A.Display the memory layout of processes
  2. B.Represent resource allocation and requests✓ Correct
  3. C.Show the CPU scheduling execution order
  4. D.Show the file system directory structure

Explanation

A resource allocation graph uses vertices (processes and resources) and edges (request edges from process to resource, assignment edges from resource to process) to represent the allocation state.

Report an error in this question

DeadlocksEasy

Q8. If a resource allocation graph has no cycle, then:

  1. A.Deadlock definitely exists in system
  2. B.Deadlock may or may not exist here
  3. C.Deadlock definitely does not exist✓ Correct
  4. D.The resource allocation graph invalid

Explanation

If the resource allocation graph contains no cycle, then no deadlock exists. A cycle is a necessary condition for deadlock. However, a cycle does not always guarantee deadlock.

Report an error in this question

DeadlocksEasy

Q9. Deadlock avoidance requires:

  1. A.Advance info about resource requests✓ Correct
  2. B.Using only one resource at a time
  3. C.Killing processes periodically needed
  4. D.No additional information at all

Explanation

Deadlock avoidance requires advance information about the maximum resource needs of each process. The system uses this to make decisions that ensure it never enters an unsafe state.

Report an error in this question

DeadlocksEasy

Q10. The Banker's Algorithm is used for:

  1. A.Checking if granting request is safe✓ Correct
  2. B.Processing banking transactions safely
  3. C.Memory allocation for new processes
  4. D.CPU scheduling of running processes

Explanation

The Banker's Algorithm is a deadlock avoidance algorithm that checks whether granting a resource request would leave the system in a safe state. If not, the request is denied.

Report an error in this question

DeadlocksMedium

Q11. A safe state is one where:

  1. A.A safe sequence exists for all processes✓ Correct
  2. B.No process is waiting for any resource
  3. C.All system resources are fully available
  4. D.No process is currently running at all

Explanation

A state is safe if there exists a sequence of all processes such that each process can be allocated its needed resources (from available + resources held by preceding processes in the sequence) to complete.

Report an error in this question

DeadlocksMedium

Q12. What is the relationship between safe state and deadlock?

  1. A.An unsafe state always guarantees that deadlock exists
  2. B.Safe state means deadlock currently exists in system
  3. C.Safe and unsafe states are unrelated to deadlock at all
  4. D.Safe means no deadlock; unsafe means deadlock may occur✓ Correct

Explanation

A safe state guarantees no deadlock. An unsafe state does not guarantee deadlock but means deadlock is possible. Deadlock avoidance ensures the system never enters an unsafe state.

Report an error in this question

DeadlocksMedium

Q13. To prevent the 'hold and wait' condition, a process must:

  1. A.Use only shared resources that do not need locking
  2. B.Never request any resources from the operating system
  3. C.Request all resources at once, or release before requesting✓ Correct
  4. D.Hold all needed resources indefinitely without releasing

Explanation

To prevent hold and wait: either a process requests all resources before starting (may cause low utilization) or it must release all currently held resources before requesting new ones.

Report an error in this question

DeadlocksMedium

Q14. To prevent circular wait, one approach is:

  1. A.Remove all shared resources from system
  2. B.Allow processes to request in any order
  3. C.Impose ordering and require increasing order✓ Correct
  4. D.Use only a single resource type allowed

Explanation

To prevent circular wait, assign a numerical ordering to all resource types and require that processes request resources in strictly increasing order of their assigned numbers.

Report an error in this question

DeadlocksMedium

Q15. In the Banker's Algorithm, the 'Need' matrix represents:

  1. A.Currently allocated resources to each process
  2. B.The total number of resources in whole system
  3. C.Remaining resources each process may still need✓ Correct
  4. D.Total resources currently available to allocate

Explanation

The Need matrix = Max - Allocation. It represents the remaining resources that each process may still request to complete its task. Need[i][j] = Max[i][j] - Allocation[i][j].

Report an error in this question

DeadlocksMedium

Q16. What is deadlock detection?

  1. A.Allowing deadlocks then detecting and recovering✓ Correct
  2. B.Ignoring deadlocks completely in all situations
  3. C.Avoiding deadlocks using the Banker Algorithm
  4. D.Preventing deadlocks from occurring in system

Explanation

Deadlock detection allows deadlocks to occur but uses algorithms to periodically check for deadlocks and then applies recovery techniques (process termination or resource preemption) to resolve them.

Report an error in this question

DeadlocksMedium

Q17. For deadlock detection with single-instance resources, which algorithm is used?

  1. A.Wait-for graph cycling✓ Correct
  2. B.Banker's Algorithm test
  3. C.Round Robin scheduling
  4. D.Best Fit allocating

Explanation

For single-instance resources, a wait-for graph is used. It is a variant of the resource allocation graph where resource nodes are removed. A cycle in the wait-for graph indicates deadlock.

Report an error in this question

DeadlocksMedium

Q18. Which deadlock recovery method terminates processes?

  1. A.Resource preemption from deadlocked processes
  2. B.Restarting the entire system from the beginning
  3. C.Ignoring the deadlock and hoping it resolves
  4. D.Process termination - abort all or one at a time✓ Correct

Explanation

Process termination can abort all deadlocked processes (expensive) or terminate one process at a time until the deadlock is broken (requires re-running detection after each termination).

Report an error in this question

DeadlocksMedium

Q19. When recovering from deadlock by process termination, which factor is NOT typically considered?

  1. A.Time it has been running
  2. B.Process priority level
  3. C.Resources it now holds
  4. D.The color of terminal✓ Correct

Explanation

When selecting a process to terminate, factors include priority, computation time completed, resources held, resources needed, number of processes to terminate, and whether it is interactive or batch.

Report an error in this question

DeadlocksMedium

Q20. The ostrich algorithm for handling deadlocks refers to:

  1. A.Ignoring deadlocks when rare and costly to handle✓ Correct
  2. B.A recovery mechanism for resolving deadlocks
  3. C.A sophisticated deadlock detection algorithm
  4. D.A prevention technique eliminating conditions

Explanation

The ostrich algorithm simply ignores deadlocks ('burying its head in the sand'). It is used when deadlocks are very rare and the cost of prevention, avoidance, or detection is deemed too high. Used by most general-purpose OSes.

Report an error in this question

DeadlocksHard

Q21. In the Banker's Algorithm safety check, what is the time complexity for n processes and m resource types?

  1. A.O(n) linear
  2. B.O(n!) factorial
  3. C.O(n * m) time
  4. D.O(n^2 * m) time✓ Correct

Explanation

The Banker's Algorithm safety check has time complexity O(n^2 * m) because in the worst case, it needs to scan all n processes n times (each scan finds at least one process that can finish), and each comparison involves m resource types.

Report an error in this question

DeadlocksHard

Q22. What is the problem with resource preemption as a deadlock recovery method?

  1. A.It uses too much memory for tracking state
  2. B.Selecting victim, rollback, preventing starvation✓ Correct
  3. C.It only works on single-processor systems
  4. D.It runs too fast and is hard to control

Explanation

Resource preemption challenges include: selecting which process to preempt (cost minimization), rolling back the preempted process to a safe state, and ensuring the same process isn't always selected (starvation).

Report an error in this question

DeadlocksHard

Q23. In a resource allocation graph with multiple instances per resource type, a cycle:

  1. A.Necessary but not sufficient✓ Correct
  2. B.Never indicates any deadlock
  3. C.Always indicates deadlock
  4. D.Neither necessary nor sufficient

Explanation

With multiple instances per resource type, a cycle is necessary but not sufficient for deadlock. A cycle may exist without deadlock if other processes can release resources to break the wait.

Report an error in this question

DeadlocksHard

Q24. What is a livelock and how does it differ from deadlock?

  1. A.There is no difference between livelock and deadlock
  2. B.Livelock only occurs in single-threaded programs only
  3. C.In livelock processes change state without any progress✓ Correct
  4. D.Livelock is simply a faster form of deadlock occurring

Explanation

In a livelock, processes are not blocked but continuously change their states in response to each other without making any real progress. Unlike deadlock, the processes are active but unproductive.

Report an error in this question

DeadlocksHard

Q25. How does the 'no preemption' condition get addressed in deadlock prevention for resources like CPU registers and memory?

  1. A.All held resources are preempted if request fails✓ Correct
  2. B.The process is immediately terminated by the OS
  3. C.These resources can never be preempted at all
  4. D.The resources are duplicated for both processes

Explanation

For preemptable resources: if a process requests a resource that is unavailable, its currently held resources are implicitly released (preempted) and added to the list of available resources.

Report an error in this question

DeadlocksHard

Q26. What is the main limitation of the Banker's Algorithm in practice?

  1. A.It runs too fast for real world use cases
  2. B.It only works with exactly two processes
  3. C.Processes rarely know max needs in advance✓ Correct
  4. D.It does not detect any resource cycles found

Explanation

The Banker's Algorithm requires each process to declare maximum resource needs in advance, which is often impractical. Additionally, the number of processes and resources changes dynamically in real systems.

Report an error in this question

DeadlocksHard

Q27. How frequently should a deadlock detection algorithm be invoked?

  1. A.Only when the system is shutting down
  2. B.Depends on frequency and tradeoff of cost✓ Correct
  3. C.Every single millisecond without exception
  4. D.Once at initial system startup only ever

Explanation

Detection frequency is a tradeoff: invoke at every resource request (expensive), at fixed intervals, or when CPU utilization drops below a threshold (suggesting possible deadlock). The choice depends on system characteristics.

Report an error in this question

DeadlocksHard

Q28. In distributed systems, what additional challenges does deadlock detection face?

  1. A.Deadlocks cannot occur in distributed systems
  2. B.Only overall performance is affected here
  3. C.No additional challenges at all exist
  4. D.Delays, no global state, phantom deadlocks✓ Correct

Explanation

In distributed systems, deadlock detection is complicated by communication delays, the absence of a global state, and the possibility of phantom (false) deadlocks detected due to outdated or inconsistent information across nodes.

Report an error in this question

DeadlocksHard

Q29. What is a two-phase locking protocol and how does it relate to deadlocks?

  1. A.A protocol using only two shared resources
  2. B.A protocol with exactly two locks only
  3. C.Growing acquires, shrinking releases; can deadlock✓ Correct
  4. D.A protocol that is completely deadlock-free

Explanation

Two-phase locking has a growing phase (acquiring locks, no releases) and shrinking phase (releasing locks, no acquisitions). It ensures serializability but does not prevent deadlocks - processes can deadlock while in the growing phase.

Report an error in this question

DeadlocksHard

Q30. What is the wound-wait scheme for deadlock prevention in database systems?

  1. A.Older wounds younger; younger waits for older✓ Correct
  2. B.A recovery technique for crashed transactions
  3. C.A method to wound and terminate processes
  4. D.A scheduling algorithm for query processing

Explanation

In wound-wait: if an older transaction needs a resource held by a younger one, the younger is 'wounded' (rolled back). If a younger transaction needs a resource held by an older one, it waits. This prevents circular wait.

Report an error in this question

Ready to test yourself on Deadlocks?

Take a timed quiz drawn from 210+ questions on this topic. No signup required — your progress saves in your browser.

Start Deadlocks Quiz