Operating System

106503
Back to Operating System

Module 4: Deadlocks

  1. 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

    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 ignoring

    View this question on its own page →
    Worked Solution

    Answer: (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.

  2. 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

    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 these

    View this question on its own page →
    Worked Solution

    Answer: (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.

  3. 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

    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 these

    View this question on its own page →
    Worked Solution

    Answer: (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.

  4. 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

    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 above

    View this question on its own page →
    Worked Solution

    Answer: (iv) All of the above

    Coffman conditions for deadlock: Mutual exclusion, Hold-and-wait, No preemption, Circular wait. All four must hold simultaneously.

  5. 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

    Which one of the following is the deadlock avoidance algorithm?

    (i) Banker's algorithm
    (ii) Round-robin algorithm
    (iii) Elevator algorithm
    (iv) Karn's algorithm

    View this question on its own page →
    Worked Solution

    Answer: (i) Banker's algorithm

    Banker's (Dijkstra) is avoidance — checks safe state before grant. Round-robin is CPU scheduling, Elevator is SCAN disk scheduling.

  6. 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

    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) 3

    View this question on its own page →
    Worked Solution

    Answer: (ii) 5

    Formula for deadlock-free guarantee with single instance type needing up to k=2 per 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.

  7. Q3b. Justify the following statement: "Cycle in resource allocation graph does not always imply the occurrence of deadlock".20234m

    Module 4: Deadlocks

    Justify the following statement: "Cycle in resource allocation graph does not always imply the occurrence of deadlock".

    View this question on its own page →
    Worked Solution

    Justification: 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.

  8. 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

    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
    View this question on its own page →
    Worked Solution

    Resource 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.

  9. 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

    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
    View this question on its own page →
    Worked Solution

    Banker'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.

  10. Q5a. Explain the core principle behind Deadlock Avoidance. Draw a Resource-allocation graph with a cycle but no deadlock.20247m

    Module 4: Deadlocks

    Explain the core principle behind Deadlock Avoidance. Draw a Resource-allocation graph with a cycle but no deadlock.

    View this question on its own page →
    Worked Solution

    Deadlock 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.

  11. Budget 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.

    Install Pocketly
  12. 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

    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
    View this question on its own page →
    Worked Solution

    Same 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.

  13. Q6a. Write necessary conditions that must hold simultaneously to arise deadlock situation. Briefly explain different deadlock handling mechanisms.20227m

    Module 4: Deadlocks

    Write necessary conditions that must hold simultaneously to arise deadlock situation. Briefly explain different deadlock handling mechanisms.

    View this question on its own page →
    Worked Solution

    Necessary 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)
  14. 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

    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.

    View this question on its own page →
    Worked Solution

    Deadlock Prevention per Condition

    1. Mutual Exclusion: make resource shareable (read-only, spooling)
    2. Hold-and-Wait: require process to request all resources at once, or release held before new request
    3. No Preemption: allow OS to preempt resources
    4. Circular Wait: impose total ordering of resource types, request in order
  15. 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

    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.

    View this question on its own page →
    Worked Solution

    Banker'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.

  16. 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

    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?

    View this question on its own page →
    Worked Solution

    Deadlock 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.

  17. Q8a. Discuss deadlock recovery techniques. Explain process termination and resource preemption methods used for recovery from deadlock.20257m

    Module 4: Deadlocks

    Discuss deadlock recovery techniques. Explain process termination and resource preemption methods used for recovery from deadlock.

    View this question on its own page →
    Worked Solution

    Deadlock 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.
  18. Q9a. Write short notes on: Banker's Algorithm20227m

    Module 4: Deadlocks

    Write short notes on: Banker's Algorithm

    View this question on its own page →
    Worked Solution

    Banker'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.