Module 3- os
Module 3- os
• Resource Vertices
Resource vertices represent the resources.
•Depending on the number of instances that exists in the
system, resource vertices may be single instance or
multiple instance.
•They are drawn as a rectangle by mentioning the dots
inside the rectangle.
•The number of dots inside the rectangle indicates the
number of instances of that resource existing in the system.
Edges
•How Many Process? Name it
•How Many Resource?.
•How instances of resource R1 ,resource R2?
•Process P1 holds ___ instance of resource ____and is waiting for an instance
of resource ____.
•Process P2 holds ____instance of resource____ and is waiting for an instance
of resource _____.
•Process P3 holds one instance of resource ____ and waiting for _______.
• When process P; requests an instance of resource type Ri, a request
edge is inserted in the resource-allocation graph.
• When this request can be fulfilled, the request edge is
instantaneously transformed to an assignment edge.
• When the process no longer needs access to the resource, it releases
the resource; as a result, the assignment edge is deleted.
• 1.If the graph contains no cycles, then no process in the system is
deadlocked.
• 2. If the graph does contain a cycle, then a deadlock may exist.
• If each resource type has exactly one instance, then a cycle implies
that a deadlock has occurred. If the cycle involves only a set of
resource types, each of which has only a single instance, then a
deadlock has occurred
RAG with Deadlock
• Given resource allocation graph is multi instance with a cycle
contained in it. So, the system may or may not be in a deadlock state.
Suppose that process P3 requests an instance of resource type
R2. Since no resource instance is currently available, a request
edge P3 ---+ R2 is added to the graph
At this point, two minimal cycles exist in the system:
Single Instance
Multiple Instance
( Resource Allocation
Graph Algorithm) (Bankers Algorithm)
Resource-Allocation-Graph Algorithm
• In addition to the request and assignment edges
already described(refer resource Allocation graph
topic), we introduce a new type of edge, called a
claim edge
• A claim edge Pi ->Rj indicates that process Pi may
request resource Rj at some time in the future
• This edge resembles a request edge in direction
but is represented in the graph by a dashed line.
• When process P1 requests resource R2, the claim
edge P1-> R2 is converted to a request edge.
Similarly, when a resource R2 is released by P1,
the assignment edge R2-> P1; is reconverted to a
claim edge p1->R2
• If no cycle exists, then the allocation of the resource will leave the
system in a safe state. If a cycle is found, then the allocation will put
the system in an unsafe state.
• Suppose that P2 requests R2 . Although R2 is currently free, we
cannot allocate it to P2, since this action will create a cycle in the
graph
Banker's Algorithm
• Bankers algorithm in Operating System is used to avoid deadlock and
for resource allocation safely to each process in the system.
• As the name suggests, it is mainly used in the banking system to
check whether the loan can be sanctioned to a person or not.
• Bankers algorithm in OS is a combination of two main algorithms:
(i) safety algorithm (to check whether the system is in a safe state or
not)
(ii) resource request algorithm (to check how the system behaves
when a process makes a resource request).
Safety Algorithm
• A safety algorithm is an algorithm used to find whether or not a
system is in its safe state. The algorithm is as follows
• Steps in Safety Algorithm are:
Bankers Algorithm in OS- To find safe sequence
solution
Example 2
(iii)