Class 11 | Deadlock Management | Operating System Notes

UNIT 4
Class 11 Operating System Deadlock Management

Deadlock Management

Original Scanned PDF – View Notes

01

Introduction

  • Deadlock is a situation when set of processes are blocked because each process is holding resource and waiting for another resource.
  • Deadlock occur when two or more processes are unable to proceed because they are waiting for each other to release resource.
  • This situation leads unable to execute process further.
Deadlock situation showing process P1 holding resource R1 and waiting for R2, while process P2 holds R2 and waits for R1 P1 P2 R1 R2 assigned to waiting for waiting for assigned to
Fig: Situation for deadlock
02

Example of Deadlock

Suppose there are two processes P1 and P2 and two resources R1 and R2.

Each process needs to access to both resources to complete it execution.

The Sequence of Events Is as Follow:

  1. P1 request R1 and gets it.
  2. P2 request R2 and gets it.
  3. P1 request R2 but it is held by P2, so P1 waits.
  4. P2 request R1 but it is held by P1, so P2 waits.

Now, neither P1 nor P2 can proceed further as they are waiting for each other to release the resources they need. This situation is called deadlock.

Process are stuck, and system in unresponsive until deadlock is resolved.

03

Necessary Condition for Deadlock

Deadlock can arise if following conditions hold simultaneously.

  1. Mutual Exclusion
  2. Hold and Wait
  3. No Preemption
  4. Circular Wait
04

1. Mutual Exclusion

  • There should be a resource that can only be held by one process at a time.
  • In diagram below, there is a single instance of Resource 1 and it is held by process 1 only.
Mutual exclusion diagram showing Process 1 allocated Resource 1 Process 1 Resource 1 Allocated
Mutual exclusion: one resource held by one process
05

2. Hold and Wait

  • A process can hold multiple resource & still request more resources from other process which are holding them.
  • In the diagram below, process-2 holds Resource-2 and Resource-3 and is requesting the Resource-1 which is held by process-1.
Hold and wait diagram showing Process 2 holding Resources 2 and 3 while requesting Resource 1 held by Process 1 Process-1 Resource-1 Process-2 Resource-2 Resource-3 allocated request allocated allocated
Fig: Hold and wait
06

3. No Preemption

  • A resource can not be preempted from a process by force.
  • A process can only release a resource voluntarily.
  • In fig below, process-2 can not preempt Resource-1 from process-1.
  • It will only be released when process-1 release it voluntarily after it execution is complete.
No preemption diagram showing Resource 1 allocated to Process 1 while Process 2 requests it and holds Resource 2 Process-1 Resource-1 Process-2 Resource-2 allocated request allocated
Fig: No preemption
07

4. Circular Wait

A process is waiting for the resource held by the second process, which is waiting for the resource held by third process and so on, till the last process is waiting for a resource held by the first process. This forms a circular wait.

For example: process-1 is allocated Resource-2 and it is requesting Resource-1. Similarly, process-2 is allocated Resource-1 and it is requesting Resource-2. This form a circular wait loop.

Circular wait diagram with Process 1, Process 2, Resource 1 and Resource 2 forming a loop Process-1 Resource-1 Resource-2 Process-2 Requested Allocated Allocated Requested
Fig: Circular wait
08

Method of Handling Deadlock

There are 3 technique to handle deadlock:

  1. Deadlock prevention
  2. Deadlock detection and recovery
  3. Deadlock avoidance
09

1. Deadlock Prevention

  • It is very important to prevent a deadlock before it can occur.
  • So, system checks each transaction before it is executed to make sure it does not lead to deadlock.
  • If there is even a slight chance that a transaction may lead to deadlock in the future, it is never allowed to execute.
10

2. Deadlock Detection and Recovery

  • A deadlock can be detected by a resource scheduler as it keeps track of all resources that are allocated to different process.
  • After deadlock is detected, it can be resolved using following method:
  1. All the process that involved in deadlock are terminated. This is not a good approach as all the progress made by the processes is destroyed.
  2. Resources can be preempted from some processes and given to other till the deadlock is resolved.
11

3. Deadlock Avoidance

  • It is better way to avoid deadlock rather than measure after the deadlock has occurred.
  • The wait for graph is used for deadlock avoidance.
  • Suitable for smaller database as it can get quite complex in layer database.
Source note: The final line is preserved as written in the scan (“layer database”), without replacing it with outside wording.
12

Wait-for Graph

The supplied notes state that the wait for graph is used for deadlock avoidance and that it is suitable for smaller database because it can get quite complex in layer database.

This is the final topic written on page 9 of the supplied scan. No additional wait-for graph diagram or worked example is included in the source PDF.

Discussion

Share a helpful question, idea, or explanation with other students.

Leave a Comment

Write a clear question, answer, or helpful explanation.
Your email will not be published.

Download Our Offline App

Study class-wise notes even when internet is not available. Get the app from Play Store.

Nepal eNotes offline app preview
Get it on Google Play