Exam Module Subscription Required
You need an active Exam Module Subscription to access this content. Subscribe now to unlock the exam materials and continue your preparation.
Video Tutorial: Banker's Algorithm, Deadlock Detection and Recovery
Video Tutorial: Banker's Algorithm, Deadlock Detection and Recovery
Total Resources Available in System: R1 = 10, R2 = 5, R3 = 7Consider the following snapshot of a system with 5 processes (P0 to P4) and 3 resource types (R1, R2, R3):

Tasks:- Calculate the Current Need matrix for each process
- Find the initial Available Resource vector
- Is the system currently in a safe state? If yes, find the safe sequence.
Consider the following snapshot of a system with 5 processes (P0 to P4) and 3 resource types (R1, R2, R3):

Tasks:
- Calculate the Current Need matrix for each process
- Find the initial Available Resource vector
- Is the system currently in a safe state? If yes, find the safe sequence.
- P0: (7, 5, 3) - (0, 1, 0) = (7, 4, 3)
- P1: (3, 2, 2) - (2, 0, 0) = (1, 2, 2)
- P2: (9, 0, 2) - (3, 0, 2) = (6, 0, 0)
- P3: (2, 2, 2) - (2, 1, 1) = (0, 1, 1)
- P4: (4, 3, 3) - (0, 0, 2) = (4, 3, 1)
First, sum up all currently allocated resources across processes:
- Total Allocated R1 = 0 + 2 + 3 + 2 + 0 = 7
- Total Allocated R2 = 1 + 0 + 0 + 1 + 0 = 2
- Total Allocated R3 = 0 + 0 + 2 + 1 + 2 = 5
Available = (10, 5, 7) - (7, 2, 5) = (3, 3, 2)
Step 3: Execution Trace (Safety Algorithm)Check if Need(P1) ≤ Available → (1, 2, 2) ≤ (3, 3, 2) — True
New Available = Available + Allocated(P1) = (3, 3, 2) + (2, 0, 0) = (5, 3, 2)
Check if Need(P3) ≤ Available → (0, 1, 1) ≤ (5, 3, 2) — True
New Available = Available + Allocated(P3) = (5, 3, 2) + (2, 1, 1) = (7, 4, 3)
Check if Need(P4) ≤ Available → (4, 3, 1) ≤ (7, 4, 3) — True
New Available = Available + Allocated(P4) = (7, 4, 3) + (0, 0, 2) = (7, 4, 5)
Check if Need(P2) ≤ Available → (6, 0, 0) ≤ (7, 4, 5) — True
New Available = Available + Allocated(P2) = (7, 4, 5) + (3, 0, 2) = (10, 4, 7)
Check if Need(P0) ≤ Available → (7, 4, 3) ≤ (10, 4, 7) — True
New Available = Available + Allocated(P0) = (10, 4, 7) + (0, 1, 0) = (10, 5, 7)
Safe Sequence: < P1, P3, P4, P2, P0 >
Consider a Resource Allocation Graph with 4 Processes P1, P2, P3, P4, and 4 Resources R1, R2, R3, R4. Find if there is a deadlock in the Graph using the Wait for Graph-based deadlock detection algorithm.


Resource Allocation Graph with 4 Processes P1, P2, P3, P4, and 3 Resources R1, R2, R3. Find if there is a deadlock in the Graph using the Wait for Graph-based deadlock detection algorithm.


Previous Job Question: Deadlock in Operating System
Previous Job Question: Deadlock in Operating System
- ☆1Operating SystemDeadlockWhat are the four necessary conditions for a deadlock to occur? Briefly explain "Circular Wait."Combined Bank, AE(IT)/AME, 26 | AME/ANE/AE
Four Necessary Conditions for Deadlock
- Mutual Exclusion: At least one resource must be held in a non-shareable mode.
- Hold and Wait: A process holds at least one resource and waits for others.
- No Preemption: Resources cannot be forcibly taken; must be released voluntarily.
- Circular Wait: A set of processes are waiting for each other in a circular chain.
Circular Wait (Explanation):
- In circular wait, each process is waiting for a resource held by another process.
- This forms a cycle (e.g., P1 → P2 → P3 → P1).
- None of the processes can proceed, causing a deadlock.
Example:
- P1 holds R1 and waits for R2
- P2 holds R2 and waits for R3
- P3 holds R3 and waits for R1

Deadlock হওয়ার চারটি শর্ত
- Mutual Exclusion: কোনো resource একসাথে একাধিক process ব্যবহার করতে পারে না।
- Hold and Wait: একটি process একটি resource ধরে রেখে অন্য resource-এর জন্য অপেক্ষা করে।
- No Preemption: resource জোর করে নেওয়া যায় না, process নিজে release করতে হয়।
- Circular Wait: process গুলো একে অপরের জন্য circular ভাবে অপেক্ষা করে।
Circular Wait (ব্যাখ্যা):
- এখানে প্রতিটি process অন্য process-এর held resource-এর জন্য অপেক্ষা করে।
- এটি একটি cycle তৈরি করে (যেমন P1 → P2 → P3 → P1)।
- কোনো process এগোতে পারে না → deadlock তৈরি হয়।
উদাহরণ:
- P1 এর কাছে R1 আছে, R2-এর জন্য অপেক্ষা করছে
- P2 এর কাছে R2 আছে, R3-এর জন্য অপেক্ষা করছে
- P3 এর কাছে R3 আছে, R1-এর জন্য অপেক্ষা করছে

- ☆2Operating SystemDeadlockWhat is Deadlock? Explain two situations where deadlock condition occurs.Janata, ASA, 21 | AME/ANE/AE
Deadlock is a situation in an Operating System where two or more processes are unable to continue execution because each process is waiting for a resource that is held by another process.
Two Situations Where Deadlock Occurs
- Mutual Exclusion: A resource can be used by only one process at a time. If another process requests the same resource, it must wait until the resource is released.
- Circular Wait: Deadlock occurs when a group of processes form a circular chain where each process is waiting for a resource held by the next process in the chain.
- ☆3Operating SystemDeadlockBriefly explain Circular Wait. In a Resource Allocation Graph (RAG), if a cycle exists, does it absolutely guarantee that a Deadlock has occurred? Explain briefly.CB, AME/AE(IT-23), 26 | AME/ANE/AE
Circular Wait
- Circular wait is one of the necessary conditions for deadlock.
- It occurs when a group of processes are waiting for resources in a circular chain.
- In this situation, each process holds at least one resource and waits for another resource held by the next process in the cycle.
Example:
- Process P1 holds Resource R1 and waits for R2.
- Process P2 holds Resource R2 and waits for R3.
- Process P3 holds Resource R3 and waits for R1.
This creates a circular waiting condition.

Cycle in Resource Allocation Graph (RAG)
If a cycle exists in a Resource Allocation Graph, it does not always guarantee deadlock.
- If each resource type has only one instance, then a cycle definitely indicates deadlock.
- If resource types have multiple instances, then a cycle may exist without deadlock.
So, a cycle is:
- A necessary condition for deadlock
- But not always a sufficient condition
Deadlock Detection using Resource Allocation Graph
To detect deadlock using Resource Allocation Graph (RAG), we follow these steps −
- If RAG contains no cycles, then there is no deadlock in the system.
- If RAG is of single instance resources and it contains a cycle, then there is a deadlock in the system.
- If RAG is of multiple instance resources and it contains a cycle, then deadlock may or may not exist. To check for deadlock, we need convert multiple instance RAG to single instance RAG, by treating each instance of a resource as a separate resource type.

In the graph:
- Resource R1 has only one instance.
- Resource R2 has two instances.
- P1 is holding R1 and requesting R2.
- P2 is holding one instance of R2 and requesting R1.
- P3 is using another instance of R2.
A cycle exists in the graph: P1 → R2 → P2 → R1 → P1
But this graph does not indicate deadlock.
Reason:
Resource R2 has multiple instances. One instance of R2 is currently allocated to P3.
If P3 finishes its work and releases R2, then:
- P1 can obtain R2 and complete execution.
- After P1 completes, it releases R1.
- Then P2 can obtain R1 and continue execution.
Since the processes can still proceed and resources can eventually be released, the system is not permanently blocked.
প্রশ্ন: Circular Wait সংক্ষেপে ব্যাখ্যা কর। Resource Allocation Graph (RAG)-এ cycle থাকলে কি নিশ্চিতভাবে Deadlock হয়েছে বোঝায়? সংক্ষেপে ব্যাখ্যা কর।
Circular Wait
- Circular wait হলো deadlock-এর একটি প্রয়োজনীয় শর্ত।
- এটি তখন ঘটে যখন একাধিক process একটি circular chain আকারে resource-এর জন্য অপেক্ষা করে।
- এখানে প্রতিটি process অন্তত একটি resource ধরে রাখে এবং পরবর্তী process-এর কাছে থাকা অন্য resource-এর জন্য অপেক্ষা করে।
উদাহরণ:
- Process P1 Resource R1 ধরে রেখে R2-এর জন্য অপেক্ষা করছে।
- Process P2 Resource R2 ধরে রেখে R3-এর জন্য অপেক্ষা করছে।
- Process P3 Resource R3 ধরে রেখে R1-এর জন্য অপেক্ষা করছে।
এভাবে একটি circular waiting condition তৈরি হয়।

Resource Allocation Graph (RAG)-এ Cycle
RAG-এ cycle থাকলেই সবসময় deadlock হয়েছে এমন নয়।
- যদি প্রতিটি resource type-এর শুধুমাত্র একটি instance থাকে, তাহলে cycle থাকলে নিশ্চিত deadlock হয়েছে।
- কিন্তু resource type-এর একাধিক instance থাকলে cycle থাকলেও deadlock নাও হতে পারে।
অতএব cycle হলো:
- Deadlock-এর জন্য একটি necessary condition
- কিন্তু সবসময় sufficient condition নয়

Graph-এ:
- Resource R1-এর একটি instance রয়েছে।
- Resource R2-এর দুটি instance রয়েছে।
- P1, R1 ধরে রেখে R2-এর জন্য অপেক্ষা করছে।
- P2, R2-এর একটি instance ধরে রেখে R1-এর জন্য অপেক্ষা করছে।
- P3, R2-এর অন্য instance ব্যবহার করছে।
Graph-এ একটি cycle রয়েছে:
P1 → R2 → P2 → R1 → P1
কিন্তু এই graph-এ deadlock নেই।
কারণ:
Resource R2-এর একাধিক instance রয়েছে। বর্তমানে R2-এর একটি instance P3 ব্যবহার করছে।
যদি P3 তার কাজ শেষ করে R2 release করে, তাহলে:
- P1, R2 পেয়ে execution সম্পন্ন করতে পারবে।
- P1 কাজ শেষ করলে R1 release করবে।
- তারপর P2, R1 পেয়ে execution চালিয়ে যেতে পারবে।
অর্থাৎ process-গুলো পরবর্তীতে execution চালিয়ে যেতে পারছে, তাই system permanently blocked নয়।
- ☆4Operating SystemDeadlockConsider the following snapshot of a system where maximum instance of A, B, C and D are 3, 14, 12 and 12.
Answer the following Question using the Bankers algorithm,
a) Calculate the need matrix from the above table?
b) Is the system in the safe state? Find out the safe sequence if no, justify the reason.BB, AD(ICT), 25 | Bangladesh Banka) answer:The Need matrix is calculated as: Need = Max - Allocation For each process, we subtract the Allocation from the Max to get the Need Matrix.

b) answer:Step-by-step checking for our system:
- P0: Needs [0, 0, 0, 0] ≤ Available [1, 5, 2, 0] → yes, so finish P0.
- Update Available by adding P0's allocation: [1, 5, 2, 0] + [0, 0, 1, 2] = [1, 5, 3, 2]
- P1: Needs [0, 7, 5, 0] ≤ Available [1, 5, 3, 2] → no, cannot finish yet.
- P2: Needs [1, 0, 0, 2] ≤ Available [1, 5, 3, 2] → yes, finish P2.
- Update Available : [1, 5, 3, 2] + [1, 3, 5, 4] = [2, 8, 8, 6]
- P3: Needs [0, 0, 2, 0] ≤ Available [2, 8, 8, 6] → yes, finish P3.
- Update Available : [2, 8, 8, 6] + [0, 6, 3, 2] = [2, 14, 11, 8]
- P4: Needs [0, 6, 4, 2] ≤ Available [2, 14, 11, 8] → yes, finish P4.
- Update Available : [2, 14, 11, 8] + [0, 0, 1, 4] = [2, 14, 12, 12]
- P1 (rechecked): Needs [0, 7, 5, 0] ≤ Available [2, 14, 12, 12] → yes, finish P1.
- Update Available : [2, 14, 12, 12] + [1, 0, 0, 0] = [3, 14, 12, 12]
Since all processes can finish in this order, the system is in a safe state.
Safe sequence: <P0, P2, P3, P4, P1>
🎥 Video Solution: Deadlock Handling (Deadlock Avoidance - Banker's Algorithm) - ☆5Operating SystemDeadlockGive the necessary condition for deadlock occur. Is it possible to have deadlock involving only a single process ? Explain your answer?Combined Bank, O(IT), 24 | Officer (IT)
Deadlock in an operating system occurs when two or more processes are stuck and cannot proceed because they are each waiting for a resource that another process holds. Essentially, the processes are in a "waiting loop," and none can continue because they are all waiting for each other to release resources.
Example: Imagine two people on a narrow staircase. One is going up, and the other is going down. Neither can move because the other person is blocking their path, and neither is willing to back up. They are stuck, waiting for the other to move first, which will never happen.
Necessary condition for occuring deadlock / Coffman Conditions
For a deadlock to happen, four conditions must all be true at the same time. These are called the Coffman conditions, named after the researchers who explained them.
- Mutual Exclusion: A resource can only be used by one process at a time. If a process is using a resource, no other process can use it until the first process releases it.
- Hold and Wait: A process is holding at least one resource and is waiting for additional resources that are currently held by other processes.
- No Preemption: Resources cannot be taken away from a process forcefully. A process can only release resources voluntarily when it is no longer needed.
- Circular Wait: A cycle exists where each process in the cycle is waiting for a resource that the next process holds. For example, Process A is waiting for Process B's resource, Process B is waiting for Process C's resource, and Process C is waiting for Process A's resource.
🎥 Video Solution: Deadlock & its Necessary Condition
✅ Can Deadlock Involve Only a Single Process?
In general, a deadlock cannot occur with only one process. The key characteristic of deadlock is that multiple processes are waiting for each other to release resources. A single process cannot create circular waiting, which is required for deadlock.




Answer the following Question using the Bankers algorithm,
1 thought on “M3: Operating System (Deadlock in Operating System)”
Vai MCQ gulote marking system ta thakle vlo hoto.
1 star, 2 star, 3 star erkm,next time jate sohojei recape kora jai