LearnFrenzy
Sign in Take a free test

Operating Systems · Topic 5 of 11

Deadlocks and Banker's Algorithm: questions with answers

The four Coffman conditions, resource-allocation graphs, prevention, avoidance with the Banker's algorithm (safety and request checks), detection, recovery and minimum-resource numericals.

Questions
45
Timed sets
3
Answers run or computed
17
Your accuracy
–

What this topic covers

8 subtopics
  • Prevention9
  • Banker's algorithm8
  • Detection8
  • Avoidance6
  • Conditions5
  • Numericals5
  • Recovery3
  • Handling1
  • Beginner 15
  • Intermediate 15
  • Advanced 15

About this topic

A deadlock is a set of processes each waiting for a resource another one holds. Questions test the four necessary conditions, how prevention, avoidance and detection differ, and above all Banker's algorithm numericals: compute the Need matrix, find a safe sequence, decide whether a request can be granted. The tables here show Allocation and Max (or Request) side by side with Available underneath; every sequence and decision was computed by running the algorithm. When several processes could finish, the lowest-numbered one is chosen first.

Free preview

Sample questions

Try each one first, then open the answer for the explanation and why the other options are wrong.

Question 1 Conditions Beginner Practice

Which four conditions must hold at the same time for a deadlock to occur?

Mutual exclusion, hold and wait, no preemption, circular wait
Circular wait, thrashing, spooling, no preemption
Race condition, busy waiting, hold and wait, paging
Mutual exclusion, starvation, aging, preemption
Show answer and explanation
Correct answer A

Explanation

These are the Coffman conditions. Deadlock prevention works by making sure at least one of them can never hold.

Why the other options are wrong

  • BThrashing and spooling are unrelated.
  • CRace conditions and paging are unrelated.
  • DStarvation and aging are scheduling ideas.
Question 2 Banker's algorithm Intermediate Practice Answer computed

Run the safety algorithm (choose the lowest-numbered process that can finish, then start scanning again from P0). Which safe sequence does it produce?

System stateAvailable: A = 3, B = 3, C = 2
ProcessAlloc AAlloc BAlloc CMax AMax BMax C
P0010753
P1200322
P2302902
P3211222
P4002433
P3P1P0P4P2
P0P1P2P3P4
P1P3P0P2P4
P1P3P4P2P0
Show answer and explanation
Correct answer C

Explanation

Need: P0 (7,4,3), P1 (1,2,2), P2 (6,0,0), P3 (0,1,1), P4 (4,3,1). Work (3,3,2): P1 fits → work (5,3,2). Rescan: P3 fits → (7,4,3). P0 fits → (7,5,3). P2 → (10,5,5). P4 → (10,5,7). (P1, P3, P4, P2, P0 from a textbook is also safe – it just uses a different choice rule.)

Why the other options are wrong

  • AWith the rule, P1 is found before P3.
  • BP0 needs 7 A but only 3 are free.
  • DAlso safe, but not what this rule produces (it picks P0 before P4).
Question 3 Numericals Advanced Practice Answer computed

Four processes need at most 3, 4, 5 and 6 units of a resource. What is the minimum number of units that guarantees the system can never deadlock?

The answer is a number – work it out, then open the solution.

Show answer and explanation
Correct answer 15

Explanation

The worst case gives each one unit short of its maximum: 2 + 3 + 4 + 5 = 14 units, all stuck. One more makes deadlock impossible: 15.

42 more questions in the timed setsSame format as the samples, with a timer, a question palette and a full review at the end.
Start practising

Operating Systems

All 11 topics

Topics, levels and full mocks
  1. 01 OS Basics and System Calls45 questions · 3 levels
  2. 02 Processes, Threads and fork()45 questions · 3 levels
  3. 03 CPU Scheduling Algorithms45 questions · 3 levels
  4. 04 Process Synchronization and Semaphores45 questions · 3 levels
  5. 05 Deadlocks and Banker's Algorithm45 questions · 3 levels
  6. 06 Memory Management and Paging45 questions · 3 levels
  7. 07 Virtual Memory and Page Replacement45 questions · 3 levels
  8. 08 File Systems and Disk Scheduling45 questions · 3 levels
  9. 09 Threads and Concurrency in Code45 questions · 3 levels
  10. 10 Linux Commands and Shell45 questions · 3 levels
  11. 11 GATE-Style OS Questions (MSQ & NAT)45 questions · 3 levels

Search LearnFrenzy

Esc

Quick links