Operating System
106503Module 4: Deadlocks
Q1f. Which technique allows the operating system to examine the resource allocation state dynamically to ensure no deadlock occurs? (i) Deadlock detection (ii) Deadlock recovery (iii) Deadlock avoidance (iv) Deadlock ignoring20252m
Module 4: Deadlocks
View this question on its own page →Which technique allows the operating system to examine the resource allocation state dynamically to ensure no deadlock occurs?
(i) Deadlock detection
(ii) Deadlock recovery
(iii) Deadlock avoidance
(iv) Deadlock ignoringWorked SolutionAnswer: (iii) Deadlock avoidance
Banker's algorithm (avoidance) dynamically checks safe state before allocating. Prevention prohibits one of four necessary conditions, Detection+Recovery allows deadlock then resolves, Ignoring (ostrich) does nothing.
Q1g. With a single resource, deadlock occurs (i) if there are more than two processes competing for that resource (ii) if there are only two processes competing for that resource (iii) if there is a single process competing for that resource (iv) none of these20232m
Module 4: Deadlocks
View this question on its own page →With a single resource, deadlock occurs
(i) if there are more than two processes competing for that resource
(ii) if there are only two processes competing for that resource
(iii) if there is a single process competing for that resource
(iv) none of theseWorked SolutionAnswer: (iv) none of these
Deadlock with single resource: a cycle + hold-and-wait can occur with ≥2 processes, but single instance per type needs cycle. With single resource instance total, deadlock impossible if max need is properly handled via ordering—question phrasing expects "none of these" as single resource deadlock requires circular wait which needs at least two processes holding different instances; trick question often marks none.
Q1g. Which of the following approach require knowledge of the system's state in advance. (i) Deadlock detection (ii) Deadlock prevention (iii) Deadlock avoidance (iv) None of these20222m
Module 4: Deadlocks
View this question on its own page →Which of the following approach require knowledge of the system's state in advance.
(i) Deadlock detection
(ii) Deadlock prevention
(iii) Deadlock avoidance
(iv) None of theseWorked SolutionAnswer: (iii) Deadlock avoidance
Avoidance (Banker's) requires knowledge of future maximum needs to compute safe state. Prevention needs only structural guarantees, Detection works after the fact.
Q1h. Which of the following conditions is required for deadlock to be possible? (i) Mutual exclusion (ii) A process may hold allocated resources while awaiting assignment of other resources (iii) No resource can be forcibly removed from a process holding it (iv) All of the above20192m
Module 4: Deadlocks
View this question on its own page →Which of the following conditions is required for deadlock to be possible?
(i) Mutual exclusion
(ii) A process may hold allocated resources while awaiting assignment of other resources
(iii) No resource can be forcibly removed from a process holding it
(iv) All of the aboveWorked SolutionAnswer: (iv) All of the above
Coffman conditions for deadlock: Mutual exclusion, Hold-and-wait, No preemption, Circular wait. All four must hold simultaneously.
Q1i. Which one of the following is the deadlock avoidance algorithm? (i) Banker's algorithm (ii) Round-robin algorithm (iii) Elevator algorithm (iv) Karn's algorithm20192m
Module 4: Deadlocks
View this question on its own page →Which one of the following is the deadlock avoidance algorithm?
(i) Banker's algorithm
(ii) Round-robin algorithm
(iii) Elevator algorithm
(iv) Karn's algorithmWorked SolutionAnswer: (i) Banker's algorithm
Banker's (Dijkstra) is avoidance — checks safe state before grant. Round-robin is CPU scheduling, Elevator is SCAN disk scheduling.
Q1j. A computer system has 6 tape drives, with *n* processes competing for them. Each process may need 2 tape drives. The maximum value of *n* for which the system is guaranteed to be deadlock free is (i) 6 (ii) 5 (iii) 4 (iv) 320232m
Module 4: Deadlocks
View this question on its own page →A computer system has 6 tape drives, with n processes competing for them. Each process may need 2 tape drives. The maximum value of n for which the system is guaranteed to be deadlock free is
(i) 6
(ii) 5
(iii) 4
(iv) 3Worked SolutionAnswer: (ii) 5
Formula for deadlock-free guarantee with single instance type needing up to
k=2per process: n*(k-1)+1 ≤ total => n*1+1 ≤6 => n≤5. So max 5 processes; 6th would allow deadlock if each holds 1 and waits for 1. (Some texts give 4 with stricter Max-need=2 → worst-case hold 1, need 1 extra, need n+1 ≤6 → n=5 same). Detailed: if each needs 2, safe sequence needs at least 1 process to complete to release.Q3b. Justify the following statement: "Cycle in resource allocation graph does not always imply the occurrence of deadlock".20234m
Module 4: Deadlocks
View this question on its own page →Justify the following statement: "Cycle in resource allocation graph does not always imply the occurrence of deadlock".
Worked SolutionJustification: Cycle in RAG implies deadlock only with single instance per resource type. With multiple instances, a cycle may not imply deadlock because another instance may satisfy request and break cycle. Example: 2 instances of R1, P1 holds R1, P2 holds R1, each requests other — cycle exists but resources can be allocated to break it. Deadlock requires cycle + each resource in cycle has only one instance (or unsatisfiable request). Hence cycle is necessary but not sufficient for multiple instances.
Q4b. A single processor system has three resource types X, Y and Z, which are shared by three processes. There are 5 units of each resource type. Consider the following scenario, where the column 'alloc' denotes the number of units of each resource type allocated to each process, and the column request denotes the number of units of each resource type requested by a process in order to complete execution. Find the process that will finish first and last. | | alloc<br>X Y Z | Request<br>X Y Z | |---|---|---| | P0 | 1 2 1 | 1 0 3 | | P1 | 2 0 1 | 0 1 2 | | P2 | 2 2 1 | 1 2 0 |20227m
Module 4: Deadlocks
View this question on its own page →A single processor system has three resource types X, Y and Z, which are shared by three processes. There are 5 units of each resource type. Consider the following scenario, where the column 'alloc' denotes the number of units of each resource type allocated to each process, and the column request denotes the number of units of each resource type requested by a process in order to complete execution. Find the process that will finish first and last.
alloc<br>X Y Z Request<br>X Y Z P0 1 2 1 1 0 3 P1 2 0 1 0 1 2 P2 2 2 1 1 2 0 Worked SolutionResource allocation X,Y,Z (5 each) alloc vs request
Total allocated: X=5(1+2+2),Y=4(2+0+2),Z=3(1+1+1) → Available =5-allocated = X0,Y1,Z2 initially? Actually given no available row, compute: assume total 5 each → Avail = Total - sumAlloc = X0,Y1,Z2. Need calc Need=Request.
Check P1 Need 0,1,2 ≤ Avail 0,1,2 → P1 can finish first, release 2,0,1 → Avail 2,1,3. Then P0 Need 1,0,3 ≤ Avail 2,1,3 → P0 finishes last? Let's simulate order P1→P0→P2 gives finish first P1, last P0/P2 depending. Detailed safe sequence P1,P2,P0 => first P1, last P0.Q4b. Consider a system with five processes P0 through P4 and four resources type A, B, C and D. Using the Banker's algorithm answer that the system is in a safe state? | Process | Allocation (A B C D) | Max (A B C D) | Available (A B C D) | | :--- | :---: | :---: | :---: | | P0 | 0 0 1 2 | 0 0 1 2 | 1 5 2 0 | | P1 | 1 0 0 0 | 1 7 5 0 | | | P2 | 1 3 5 4 | 2 3 5 6 | | | P3 | 0 6 3 2 | 0 6 5 2 | | | P4 | 0 0 1 4 | 0 6 5 6 | |20257m
Module 4: Deadlocks
View this question on its own page →Consider a system with five processes P0 through P4 and four resources type A, B, C and D. Using the Banker's algorithm answer that the system is in a safe state?
Process Allocation (A B C D) Max (A B C D) Available (A B C D) P0 0 0 1 2 0 0 1 2 1 5 2 0 P1 1 0 0 0 1 7 5 0 P2 1 3 5 4 2 3 5 6 P3 0 6 3 2 0 6 5 2 P4 0 0 1 4 0 6 5 6 Worked SolutionBanker's Safe State Check (5 processes A-D)
Available 1,5,2,0. Need = Max-Alloc.
P0 Need 0,0,0,0 → can run, completes, releases 0,0,1,2 → Avail 1,5,3,2.
P3 Need 0,0,2,0 ≤ Avail → run → Avail 1,11,6,4.
P1 Need 0,7,5,0 ≤ Avail → run → Avail 2,11,6,4.
P2 Need 1,0,0,2 ≤ Avail → run → Avail 3,14,11,8.
P4 Need 0,6,4,2 ≤ Avail → finishes.
Safe sequence P0→P3→P1→P2→P4 exists, so system is safe.Q5a. Explain the core principle behind Deadlock Avoidance. Draw a Resource-allocation graph with a cycle but no deadlock.20247m
Module 4: Deadlocks
View this question on its own page →Explain the core principle behind Deadlock Avoidance. Draw a Resource-allocation graph with a cycle but no deadlock.
Worked SolutionDeadlock Avoidance Principle
Requires safe state check before grant. Resource allocation graph with cycle but no deadlock: use multiple instances. Example: 2 instances of R1, P1 holds R1, P2 holds R1, P1 requests R2, P2 requests R2 held elsewhere — cycle exists but extra instance breaks deadlock. Draw RAG with cycle and extra resource free.
- Install PocketlyBudget App•POCKETLY
Pocketly on Android
Log daily food, travel, and hostel expenses instantly. Set monthly spending limits and see where your money goes without complex spreadsheets.
Q5b. Consider a system with five processes P0 through P4 and four resources type A, B, C and D. Using the Banker's algorithm answer that the system is in a safe state? | | Allocation | Max | Available | | :--- | :--- | :--- | :--- | | | A B C D | A B C D | A B C D | | P0 | 0 0 1 2 | 0 0 1 2 | 1 5 2 0 | | P1 | 1 0 0 0 | 1 7 5 0 | | | P2 | 1 3 5 4 | 2 3 5 6 | | | P3 | 0 6 3 2 | 0 6 5 2 | | | P4 | 0 0 1 4 | 0 6 5 6 | |20247m
Module 4: Deadlocks
View this question on its own page →Consider a system with five processes P0 through P4 and four resources type A, B, C and D. Using the Banker's algorithm answer that the system is in a safe state?
Allocation Max Available A B C D A B C D A B C D P0 0 0 1 2 0 0 1 2 1 5 2 0 P1 1 0 0 0 1 7 5 0 P2 1 3 5 4 2 3 5 6 P3 0 6 3 2 0 6 5 2 P4 0 0 1 4 0 6 5 6 Worked SolutionSame as Q113 — Banker's safe sequence P0→P3→P1→P2→P4, system is safe. Need = Max-Alloc, check Available 1,5,2,0. P0 need 0 passes, then P3 etc. Detailed as previous.
Q6a. Write necessary conditions that must hold simultaneously to arise deadlock situation. Briefly explain different deadlock handling mechanisms.20227m
Module 4: Deadlocks
View this question on its own page →Write necessary conditions that must hold simultaneously to arise deadlock situation. Briefly explain different deadlock handling mechanisms.
Worked SolutionNecessary Conditions (Coffman)
1 Mutual Exclusion 2 Hold-and-Wait 3 No Preemption 4 Circular Wait
Handling
- Prevention (break one condition)
- Avoidance (Banker's, safe state)
- Detection & Recovery (wait-for graph, kill/preempt)
- Ignorance (ostrich, used by Unix/Windows)
Q6a. For a deadlock to occur, each of the necessary conditions must hold. By ensuring that at least one of these conditions cannot hold, we can prevent the occurrence of a deadlock. Give one approach individually to prevent each of these necessary conditions.20237m
Module 4: Deadlocks
View this question on its own page →For a deadlock to occur, each of the necessary conditions must hold. By ensuring that at least one of these conditions cannot hold, we can prevent the occurrence of a deadlock. Give one approach individually to prevent each of these necessary conditions.
Worked SolutionDeadlock Prevention per Condition
- Mutual Exclusion: make resource shareable (read-only, spooling)
- Hold-and-Wait: require process to request all resources at once, or release held before new request
- No Preemption: allow OS to preempt resources
- Circular Wait: impose total ordering of resource types, request in order
Q6b. Consider a system with five processes P0 through P4 and have three resource types A, B, C. Resource type A has ten instances, resource type B has five instances, and resource type C has seven instances. Suppose that the following snapshot represents the current state of the system: | | Allocation | Max | Available | | :--- | :---: | :---: | :---: | | | A B C | A B C | A B C | | P0 | 0 1 0 | 7 5 3 | 3 3 2 | | P1 | 2 0 0 | 3 2 2 | | | P2 | 3 0 2 | 9 0 2 | | | P3 | 2 1 1 | 2 2 2 | | | P4 | 0 0 2 | 4 3 3 | | The system is currently in safe state. Suppose now that P1 requests additional resources as (A=1, B=0, C=2). Is this request can be immediately granted? Justify your answer.20237m
Module 4: Deadlocks
View this question on its own page →Consider a system with five processes P0 through P4 and have three resource types A, B, C. Resource type A has ten instances, resource type B has five instances, and resource type C has seven instances. Suppose that the following snapshot represents the current state of the system:
Allocation Max Available A B C A B C A B C P0 0 1 0 7 5 3 3 3 2 P1 2 0 0 3 2 2 P2 3 0 2 9 0 2 P3 2 1 1 2 2 2 P4 0 0 2 4 3 3 The system is currently in safe state. Suppose now that P1 requests additional resources as (A=1, B=0, C=2). Is this request can be immediately granted? Justify your answer.
Worked SolutionBanker's Request P1 (1,0,2) with Available 3,3,2
Check Need P1 = Max-Alloc = 1,2,2. Request 1,0,2 ≤ Need (1,2,2) and ≤ Available (3,3,2) → pretend allocate: Avail becomes 2,3,0, Alloc P1 becomes 3,0,2.
Check safe: Need remaining: P0 7,4,3, P1 0,2,0, P2 6,0,0, P3 0,1,1, P4 4,3,1. No safe sequence because Avail 2,3,0 insufficient for any Need → request cannot be granted, would lead to unsafe state, P1 must wait.Q8. Define deadlock. List four necessary conditions for occurrence of deadlock. A system contains six units of resource, and *n* processes that use the resource. What is the maximum value of *n* for which the system will be deadlock free if the maximum requirement of each process is 3?201914m
Module 4: Deadlocks
View this question on its own page →Define deadlock. List four necessary conditions for occurrence of deadlock.
A system contains six units of resource, and n processes that use the resource. What is the maximum value of n for which the system will be deadlock free if the maximum requirement of each process is 3?
Worked SolutionDeadlock Definition & Conditions
Deadlock = set of processes blocked each waiting for resource held by another, circular wait.
Four Coffman conditions: Mutual Exclusion, Hold-and-Wait, No Preemption, Circular Wait.
Max n for 6 units, need 3 per process: For deadlock-free, n*(need-1)+1 ≤6 → n*2+1≤6 → n≤2 (integer). So n=2 deadlock-free, n=3 may deadlock. Some texts give n=2.Q8a. Discuss deadlock recovery techniques. Explain process termination and resource preemption methods used for recovery from deadlock.20257m
Module 4: Deadlocks
View this question on its own page →Discuss deadlock recovery techniques. Explain process termination and resource preemption methods used for recovery from deadlock.
Worked SolutionDeadlock Recovery
- Process termination: abort all deadlocked or one by one (victim selection by priority/cost), rollback.
- Resource preemption: preempt resources, roll back process to safe state, starvation avoidance. Requires selecting victim, rollback, starvation prevention.
Q9a. Write short notes on: Banker's Algorithm20227m
Module 4: Deadlocks
View this question on its own page →Write short notes on: Banker's Algorithm
Worked SolutionBanker's Algorithm
Safe-state avoidance algorithm. Data: Available, Max, Allocation, Need=Max-Alloc. Safety check finds safe sequence where each Need ≤ Available + releases. Request grant checks Request≤Need and Request≤Available then simulates safety. Ensures deadlock avoidance.