You are on page 1of 16

OS LECTURE-1

• MUTE ALL AUDIO AND VIDEO


• WRITE YOUR ROLL NO AND NAME ON CHAT
BOX
• Lecture is going to start in 5minutes.
MODULE-3
DEADLOCK-
A process in operating systems uses
different resources and uses resources in
following way.
1) Requests a resource
2) Use the resource
2) Releases the resource
CONDITIONS
Deadlock can arise if following four conditions hold
simultaneously (Necessary Conditions)
• Mutual Exclusion: One or more than one resource are
non-sharable (Only one process can use at a time)
• Hold and Wait: A process is holding at least one
resource and waiting for resources.
• No Preemption: A resource cannot be taken from a
process unless the process releases the resource.
• Circular Wait: A set of processes are waiting for each
other in circular form.
Deadlock avoidance
• If a system is already in a safe state, we can try to
stay away from an unsafe state and avoid
deadlock. Deadlocks cannot be avoided in an
unsafe state. A system can be considered to be in
safe state if it is not in a state of deadlock and can
allocate resources upto the maximum available. A
safe sequence of processes and allocation of
resources ensures a safe state. Deadlock
avoidance algorithms try not to allocate
resources to a process if it will make the system in
an unsafe state.
Deadlock avoidance
• RESOURCE ALLOCATION GRAPH
• BANKER’S ALGO
• SAFE AND UNSAFE STATE
resource allocation graph
• A resource allocation graph is generally used
to avoid deadlocks. If there are no cycles in
the resource allocation graph, then there are
no deadlocks.
• The resource allocation graph has request
edges and assignment edges. An edge from a
process to resource is a request edge and an
edge from a resource to process is an
allocation edge.
resource allocation graph
• Consider the image • If R2 is allocated to p2
• with calm edges as and if P1 request for R2,
below: there will be a
deadlock.
DEADLOCK DETECTION
DEADLOCK DETECTION
• In the BELOW diagram,
• If resources have single resource 1 and resource 2
instance: have single instances.
In this case for Deadlock There is a cycle R1 → P1
detection we can run an → R2 → P2. So, Deadlock
algorithm to check for is Confirmed.
cycle in the Resource
Allocation Graph.
Presence of cycle in the
graph is the sufficient
condition for deadlock.


DEADLOCK DETECTION

2. If there are multiple instances of resources:


Detection of the cycle is necessary but not
sufficient condition for deadlock detection, in
this case, the system may or may not be in
deadlock varies according to different
situations.
Deadlock Recovery
Deadlock Recovery
• Killing the process: killing all the process involved
in the deadlock. Killing process one by one. After
killing each process check for deadlock again keep
repeating the process till system recover from
deadlock.
• Resource Preemption: Resources are preempted
from the processes involved in the deadlock,
preempted resources are allocated to other
processes so that there is a possibility of
recovering the system from deadlock. In this case,
the system goes into starvation
Monitors in Process Synchronization

• The monitor is one of the ways to achieve


Process synchronization. The monitor is
supported by programming languages to
achieve mutual exclusion between processes.
Monitors in Process Synchronization
• It is the collection of condition variables and
procedures combined together in a special
kind of module or a package.
• The processes running outside the monitor
can’t access the internal variable of the
monitor but can call procedures of the
monitor.
• Only one process at a time can execute code
inside monitors.
ASSIGNMENT FOR TODAY

• WHAT IS STARVATION? EXPLAIN WITH ITS


SOLUTION.
Thank you!!

Any Queries???

You might also like