0% found this document useful (0 votes)
39 views16 pages

University Institute of Engineering (UIE)

This document discusses deadlocks in operating systems. It defines deadlocks as blocked processes each holding a resource and waiting for a resource held by another process. It outlines the four necessary conditions for deadlock: mutual exclusion, hold and wait, no preemption, and circular wait. It also discusses resource allocation graphs and how they can be used to identify deadlocks. It provides concepts like maximum and minimum number of resources needed to ensure or prevent deadlocks.

Uploaded by

Sarthak Thakur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views16 pages

University Institute of Engineering (UIE)

This document discusses deadlocks in operating systems. It defines deadlocks as blocked processes each holding a resource and waiting for a resource held by another process. It outlines the four necessary conditions for deadlock: mutual exclusion, hold and wait, no preemption, and circular wait. It also discusses resource allocation graphs and how they can be used to identify deadlocks. It provides concepts like maximum and minimum number of resources needed to ensure or prevent deadlocks.

Uploaded by

Sarthak Thakur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 16

Department of Computer Science and Engineering (CSE)

University Institute of Engineering (UIE)


Lecture9
Deadlocks

List-of-content
Deadlocks: Deadlock characterization and conditions for deadlock,
deadlock prevention, Deadlock avoidance-safe state, resource
allocation graph algorithm, Banker’s algorithms-Safety algorithm,
Deadlock detection, Recovery from deadlock.

University Institute of Engineering (UIE)


Deadlocks
Deadlocks are a set of blocked processes each holding a resource and waiting to acquire
a resource held by another process.

University Institute of Engineering (UIE)


Necessary Conditions for Deadlock

.
There are four conditions that are necessary to achieve deadlock:
Mutual Exclusion - At least one resource must be held in a non-sharable mode;
If any other process requests this resource, then that process must wait for the
resource to be released.
Hold and Wait - A process must be simultaneously holding at least one
resource and waiting for at least one resource that is currently being held by
some other process.
No preemption - Once a process is holding a resource ( i.e. once its request has
been granted ), then that resource cannot be taken away from that process
until the process voluntarily releases it.
Circular Wait - A set of processes { P0, P1, P2, . . ., PN } must exist such that
every P[ i ] is waiting for P[ ( i + 1 ) % ( N + 1 ) ]. ( Note that this condition
implies the hold-and-wait condition, but it is easier to deal with the conditions
if the four are considered separately. )

University Institute of Engineering (UIE)


System Model

•Resource types R1, R2, . . ., Rm


•CPU cycles, memory space, I/O devices
•Each resource type Ri has Wi instances.
•Each process utilizes a resource as follows:
• request
• use
• release

University Institute of Engineering (UIE)


Resource-Allocation Graph

In some cases deadlocks can be understood more clearly through the use
of Resource-Allocation Graphs, having the following properties:

A set of resource categories, { R1, R2, R3, . . ., RN }, which appear as square


nodes on the graph. Dots inside the resource nodes indicate specific instances
of the resource. ( E.g. two dots might represent two laser printers. )

A set of processes, { P1, P2, P3, . . ., PN }

University Institute of Engineering (UIE)


Resource-Allocation Graph

Request Edges - A set of directed arcs from Pi to Rj, indicating that process
Pi has requested Rj, and is currently waiting for that resource to become
available.

Assignment Edges - A set of directed arcs from Rj to Pi indicating that


resource Rj has been allocated to process Pi, and that Pi is currently holding
resource Rj.

Note that a request edge can be converted into an assignment edge by


reversing the direction of the arc when the request is granted. ( However
note also that request edges point to the category box, whereas assignment
edges emanate from a particular instance dot within the box. )

University Institute of Engineering (UIE)


Resource-Allocation Graph (Cont.)

 Process

 Resource Type with 4 instances

 Pi requests instance of Rj
Pi Rj

 Pi is holding an instance of Rj

University Institute of Engineering (UIE)


Resource-Allocation Graph (Cont.)

Resource allocation graph

University Institute of Engineering (UIE)


Resource-Allocation Graph (Cont.)

Resource allocation graph with a


deadlock

University Institute of Engineering (UIE)


Resource-Allocation Graph
(Cont.)
.

Resource allocation graph with a cycle but no deadlock

University Institute of Engineering (UIE)


Basic Facts

If graph contains no cycles  no deadlock


If graph contains a cycle 
if only one instance per resource type, then deadlock
if several instances per resource type, possibility
of deadlock

University Institute of Engineering (UIE)


Important Concept
Consider there are n processes in the system P 1, P2, P3, …… , Pn where-
Process P1 requires x1 units of resource R
Process P2 requires x2 units of resource R
Process P3 requires x3 units of resource R and so on.
In worst case,
The number of units that each process holds = One less than its maximum demand
So,
Process P1 holds x1 – 1 units of resource R
Process P2 holds x2 – 1 units of resource R
Process P3 holds x3 – 1 units of resource R and so on.
Now,
If one more unit of resource R is present in the system, then system could be ensured deadlock
free.
This is because that unit would be allocated to one of the processes and it would get execute and
then release its units.

University Institute of Engineering (UIE)


Important Concept
Maximum Number Of Units That Ensures Deadlock-

Maximum number of units of resource R that ensures deadlock


= (x1-1) + (x2-1) + (x3-1) + …. + (xn-1)
= ( x1 + x2 + x3 + …. + xn ) – n
= ∑xi – n
= Sum of max needs of all n processes – n

Minimum Number Of Units That Ensures No Deadlock-

Minimum number of units of resource R that ensures no deadlock


= One more than maximum number of units of resource R that ensures deadlock
= (∑xi – n) + 1

University Institute of Engineering (UIE)


Conclusion

This lecture enables the students to understand what is a


deadlock, necessary conditions for deadlock, resource
allocation graph other important concepts of deadlocks.

University Institute of Engineering (UIE)


References
https://www.includehelp.com/c-programming-questions/

https://www.studytonight.com/operating-system/

https://computing.llnl.gov/tutorials/

https://www.tutorialspoint.com/operating_system/index.htm#:~:text=An%20operating%20sy
stem%20(OS)%20is,software%20in%20a%20computer%20system.

https://www.javatpoint.com/os-tutorial

https://www.guru99.com/operating-system-tutorial.html
https://www.geeksforgeeks.org/operating-systems/

University Institute of Engineering (UIE)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy