0% found this document useful (0 votes)
44 views25 pages

Os 3 Unit

Uploaded by

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

Os 3 Unit

Uploaded by

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

UNIT-3

What is Deadlock in Operating System (OS)?


Every process needs some resources to complete its execution. However, the resource
is granted in a sequential order.

1. The process requests for some resource.


2. OS grant the resource if it is available otherwise let the process waits.
3. The process uses it and release on the completion.

A Deadlock is a situation where each of the computer process waits for a resource which
is being assigned to some another process. In this situation, none of the process gets
executed since the resource it needs, is held by some other process which is also waiting
for some other resource to be released.

Let us assume that there are three processes P1, P2 and P3. There are three different
resources R1, R2 and R3. R1 is assigned to P1, R2 is assigned to P2 and R3 is assigned
to P3.

After some time, P1 demands for R1 which is being used by P2. P1 halts its execution
since it can't complete without R2. P2 also demands for R3 which is being used by P3. P2
also stops its execution because it can't continue without R3. P3 also demands for R1
which is being used by P1 therefore P3 also stops its execution.

In this scenario, a cycle is being formed among the three processes. None of the process
is progressing and they are all waiting. The computer becomes unresponsive since all the
processes got blocked.

Difference between Starvation and Deadlock

Sr. Deadlock Starvation


Starvation is a situation
Deadlock is a situation
where the low priority
where no process got
1 process got blocked and the
blocked and no process
high priority processes
proceeds
proceed.

Deadlock is an infinite Starvation is a long waiting


2
waiting. but not infinite.

Every Deadlock is always a Every starvation need not


3
starvation. be deadlock.

The requested resource is The requested resource is


4 blocked by the other continuously be used by the
process. higher priority processes.

Deadlock happens when


Mutual exclusion, hold and It occurs due to the
5 wait, No preemption and uncontrolled priority and
circular wait occurs resource management.
simultaneously.

Necessary conditions for Deadlocks


1. Mutual Exclusion

A resource can only be shared in mutually exclusive manner. It implies, if two


process cannot use the same resource at the same time.

2. Hold and Wait

A process waits for some resources while holding another resource at the same
time.

3. No preemption

The process which once scheduled will be executed till the completion. No other
process can be scheduled by the scheduler meanwhile.

4. Circular Wait

All the processes must be waiting for the resources in a cyclic manner so that the
last process is waiting for the resource which is being held by the first process.
Deadlock Prevention
If we simulate deadlock with a table which is standing on its four legs then we can also
simulate four legs with the four conditions which when occurs simultaneously, cause the
deadlock.

However, if we break one of the legs of the table then the table will fall definitely. The
same happens with deadlock, if we can be able to violate one of the four necessary
conditions and don't let them occur together then we can prevent the deadlock.

Let's see how we can prevent each of the conditions.

1. Mutual Exclusion
Mutual section from the resource point of view is the fact that a resource can never be
used by more than one process simultaneously which is fair enough but that is the main
reason behind the deadlock. If a resource could have been used by more than one
process at the same time then the process would have never been waiting for any
resource.

However, if we can be able to violate resources behaving in the mutually exclusive manner
then the deadlock can be prevented.

Spooling
For a device like printer, spooling can work. There is a memory associated with the printer
which stores jobs from each of the process into it. Later, Printer collects all the jobs and
print each one of them according to FCFS. By using this mechanism, the process doesn't
have to wait for the printer and it can continue whatever it was doing. Later, it collects the
output when it is produced.

Although, Spooling can be an effective approach to violate mutual exclusion but it suffers
from two kinds of problems.
1. This cannot be applied to every resource.
2. After some point of time, there may arise a race condition between the processes
to get space in that spool.

We cannot force a resource to be used by more than one process at the same time since
it will not be fair enough and some serious problems may arise in the performance.
Therefore, we cannot violate mutual exclusion for a process practically.

2. Hold and Wait


Hold and wait condition lies when a process holds a resource and waiting for some other
resource to complete its task. Deadlock occurs because there can be more than one
process which are holding one resource and waiting for other in the cyclic order.

However, we have to find out some mechanism by which a process either doesn't hold
any resource or doesn't wait. That means, a process must be assigned all the necessary
resources before the execution starts. A process must not wait for any resource once the
execution has been started.

Advertisement

!(Hold and wait) = !hold or !wait (negation of hold and wait is, either you don't hold
or you don't wait)

This can be implemented practically if a process declares all the resources initially.
However, this sounds very practical but can't be done in the computer system because a
process can't determine necessary resources initially.

Process is the set of instructions which are executed by the CPU. Each of the instruction
may demand multiple resources at the multiple times. The need cannot be fixed by the
OS.

The problem with the approach is:

1. Practically not possible.


2. Possibility of getting starved will be increases due to the fact that some process
may hold a resource for a very long time.

3. No Preemption
Deadlock arises due to the fact that a process can't be stopped once it starts. However, if
we take the resource away from the process which is causing deadlock then we can
prevent deadlock.

This is not a good approach at all since if we take a resource away which is being used
by the process then all the work which it has done till now can become inconsistent.

Consider a printer is being used by any process. If we take the printer away from that
process and assign it to some other process then all the data which has been printed can
become inconsistent and ineffective and also the fact that the process can't start printing
again from where it has left which causes performance inefficiency.
Advertisement

4. Circular Wait
To violate circular wait, we can assign a priority number to each of the resource. A process
can't request for a lesser priority resource. This ensures that not a single process can
request a resource which is being utilized by some other process and no cycle will be
formed.

Among all the methods, violating Circular wait is the only approach that can be
implemented practically.

Deadlock avoidance
In deadlock avoidance, the request for any resource will be granted if the resulting state
of the system doesn't cause deadlock in the system. The state of the system will
continuously be checked for safe and unsafe states.

In order to avoid deadlocks, the process must tell OS, the maximum number of resources
a process can request to complete its execution.

The simplest and most useful approach states that the process should declare the
maximum number of resources of each type it may ever need. The Deadlock avoidance
algorithm examines the resource allocations so that there can never be a circular wait
condition.

Safe and Unsafe States

The resource allocation state of a system can be defined by the instances of available and
allocated resources, and the maximum instance of the resources demanded by the
processes.
A state of a system recorded at some random time is shown below.

Resources Assigned

Process Type 1 Type 2 Type 3 Type 4

A 3 0 2 2

B 0 0 1 1

C 1 1 1 0

D 2 1 4 0

Resources still needed

Process Type 1 Type 2 Type 3 Type 4

A 1 1 0 0

B 0 1 1 2

C 1 2 1 0

D 2 1 1 2

1. E = (7 6 8 4)
2. P = (6 2 8 3)
3. A = (1 4 0 1)

Above tables and vector E, P and A describes the resource allocation state of a system.
There are 4 processes and 4 types of the resources in a system. Table 1 shows the
instances of each resource assigned to each process.

Table 2 shows the instances of the resources, each process still needs. Vector E is the
representation of total instances of each resource in the system.
Vector P represents the instances of resources that have been assigned to processes.
Vector A represents the number of resources that are not in use.

Deadlock Detection and Recovery


In this approach, The OS doesn't apply any mechanism to avoid or prevent the deadlocks.
Therefore the system considers that the deadlock will definitely occur. In order to get rid
of deadlocks, The OS periodically checks the system for any deadlock. In case, it finds
any of the deadlock then the OS will recover the system using some recovery techniques.

The main task of the OS is detecting the deadlocks. The OS can detect the deadlocks
with the help of Resource allocation graph.

In 1. single instanced resource types, if a cycle is being formed in the system then there
will definitely be a deadlock. On the other hand, in2. multiple instanced resource type
graph, detecting a cycle is not just enough. We have to apply the safety algorithm on the
system by converting the resource allocation graph into the allocation matrix and request
matrix.

3. Wait-For Graph Algorithm


The Wait-For Graph Algorithm is a deadlock detection algorithm used to
detect deadlocks in a system where resources can have multiple instances.
The algorithm works by constructing a Wait-For Graph, which is a directed
graph that represents the dependencies between processes and resources.

Wait For Graph Deadlock Detection in


Distributed System
Last Updated : 28 Apr, 2022

Deadlocks are a fundamental problem in distributed systems. A process may request
resources in any order and a process can request resources while holding others. A
Deadlock is a situation where a set of processes are blocked as each process in a
Distributed system is holding some resources and that acquired resources are needed
by some other processes.
Example:
If there are three processes p1,p2 and p1 are acquiring r1 resource and that r1 is
needed by p2 which is acquiring another resource r2 and that is needed by p1. Here
cycle occurs. It is called a deadlock.

Here in the above graph we found a cycle from P1 to P2 and again to P1. So we can
say that the system is in a deadlock state.
The Problem of deadlocks has been generally studied in distributed systems under
the following models :
 The system has only reusable resources.
 Processes are allowed only exclusive access to resources.
 There is only one copy of each resource.
Deadlock Detection:
The deadlock Detection Algorithm is of two types:
 Wait-for-Graph Algorithm (Single Instance)
 Banker’s Algorithm (Multiple Instance)
Wait-for-Graph Algorithm: It is a variant of the Resource Allocation graph. In this
algorithm, we only have processes as vertices in the graph. If the Wait-for-Graph
contains a cycle then we can say the system is in a Deadlock state. Now we will
discuss how the Resource Allocation graph will be converted into Wait-for-Graph
in an Algorithmic Approach. We need to remove resources while converting from
Resource Allocation Graph to Wait-for-Graph.
 Resource Allocation Graph: Contains Processes and Resources.
 Wait-for-Graph: Contains only Processes after removing the Resources while
conversion from Resource Allocation Graph.
Algorithm:
Step 1: Take the first process (Pi) from the resource allocation graph and check the
path in which it is acquiring resource (Ri), and start a wait-for-graph with that
particular process.
Step 2: Make a path for the Wait-for-Graph in which there will be no Resource
included from the current process (Pi) to next process (Pj), from that next process (Pj)
find a resource (Rj) that will be acquired by next Process (Pk) which is released from
Process (Pj).
Step 3: Repeat Step 2 for all the processes.
Step 4: After completion of all processes, if we find a closed-loop cycle then the
system is in a deadlock state, and deadlock is detected.
Now we will see the working of this Algorithm with an Example. Consider a
Resource Allocation Graph with 4 Processes P1, P2, P3, P4, and 4 Resources R1,
R2, R3, R4. Find if there is a deadlock in the Graph using the Wait for Graph-based
deadlock detection algorithm.

Step 1: First take Process P1 which is waiting for Resource R1, resource R1 is
acquired by Process P2, Start a Wait-for-Graph for the above Resource Allocation
Graph.
Step 2: Now we can observe that there is a path from P1 to P2 as P1 is waiting for
R1 which is been acquired by P2. Now the Graph would be after removing resource
R1 looks like.

Step 3: From P2 we can observe a path from P2 to P3 as P2 is waiting for R4 which


is acquired by P3. So make a path from P2 to P3 after removing resource R4 looks
like.
Step 4: From P3 we find a path to P4 as it is waiting for P3 which is acquired by P4.
After removing R3 the graph looks like this.

Step 5: Here we can find Process P4 is waiting for R2 which is acquired by P1. So
finally the Wait-for-Graph is as follows:
Step 6: Finally In this Graph, we found a cycle as the Process P4 again came back
to the Process P1 which is the starting point (i.e., it’s a closed-loop). So, According
to the Algorithm if we found a closed loop, then the system is in a deadlock state.
So here we can say the system is in a deadlock state.

Now consider another Resource Allocation Graph with 4 Processes P1, P2, P3, P4,
and 3 Resources R1, R2, R3. Find if there is a deadlock in the Graph using the Wait
for Graph-based deadlock detection algorithm.
Step 1: First take Process P1 which is waiting for Resource R1, resource R1 is
acquired by Process P2, Start a Wait-for-Graph for the above Resource Allocation
Graph.

Step 2: Now we can observe that there is a path from P1 to P2 and also from P1 to
P4 as P1 is waiting for R1 which is been acquired by P2 and P1 is also waiting for
R2 which is acquired by P4. Now the Graph would be after removing resources R1
and R2 looks like.

Step 3: From P2 we can observe a path from P2 to P3 as P2 is waiting for R3 which


is acquired by P3. So make a path from P2 to P3 after removing resource R3 looks
like.
Step 4: Here we can find Process P4 is waiting for R3 which is acquired by P3. So
finally the Wait-for-Graph looks like after removing Resource R3 looks like.

Step 5: In this Graph, we don’t find a cycle as no process came back to the starting
point (i.e., there is no closed loop). So, According to the Algorithm if we found a
closed loop, then the system is in a deadlock state. But here we didn’t find any closed
loop so the system is not in a deadlock state. The system is in a safe state.
Note: In Example 2, even though it looks like a loop but there is no process that has
reached the first process, or starting point again. So there is no closed loop.
Issues in Wait-for-Graph based Deadlock Detection Algorithm :
For every resource we call WFG Detection Algorithm, the computation time would
be very high for the CPU if there are many resources. The solution for this is, rather
than calling this algorithm for every resource request that cannot be granted
immediately. Just invoke the algorithm after a definite interval.

In order to recover the system from deadlocks, either OS considers resources or


processes.

For Resource

Preempt the resource


We can snatch one of the resources from the owner of the resource (process) and give it
to the other process with the expectation that it will complete the execution and will release
this resource sooner. Well, choosing a resource which will be snatched is going to be a
bit difficult.

Rollback to a safe state


System passes through various states to get into the deadlock state. The operating system
canrollback the system to the previous safe state. For this purpose, OS needs to
implement check pointing at every state.
The moment, we get into deadlock, we will rollback all the allocations to get into the
previous safe state.

For Process

Kill a process
Killing a process can solve our problem but the bigger concern is to decide which process
to kill. Generally, Operating system kills a process which has done least amount of work
until now.

Kill all process


This is not a suggestible approach but can be implemented if the problem becomes very
serious. Killing all process will lead to inefficiency in the system because all the processes
will execute again from starting.

 Concurrency Control: Concurrency control mechanisms are used to


prevent data inconsistencies in systems with multiple concurrent
processes. These mechanisms ensure that concurrent processes do
not access the same data at the same time, which can lead to
inconsistencies and errors. Deadlocks can occur in concurrent systems
when two or more processes are blocked, waiting for each other to
release the resources they need. This can result in a system-wide stall,
where no process can make progress. Concurrency control
mechanisms can help prevent deadlocks by managing access to
shared resources and ensuring that concurrent processes do not
interfere with each other.
Resource Allocation Graph
The resource allocation graph is the pictorial representation of the state of a system. As
its name suggests, the resource allocation graph is the complete information about all the
processes which are holding some resources or waiting for some resources.

It also contains the information about all the instances of all the resources whether they
are available or being used by the processes.

In Resource allocation graph, the process is represented by a Circle while the Resource
is represented by a rectangle. Let's see the types of vertices and edges in detail.

Vertices are mainly of two types, Resource and process. Each of them will be represented
by a different shape. Circle represents process while rectangle represents resource.

A resource can have more than one instance. Each instance will be represented by a dot
inside the rectangle.
Edges in RAG are also of two types, one represents assignment and other represents the
wait of a process for a resource. The above image shows each of them.

A resource is shown as assigned to a process if the tail of the arrow is attached to an


instance to the resource and the head is attached to a process.

A process is shown as waiting for a resource if the tail of an arrow is attached to the
process while the head is pointing towards the resource.

Example
Let'sconsider 3 processes P1, P2 and P3, and two types of resources R1 and R2. The
resources are having 1 instance each.
According to the graph, R1 is being used by P1, P2 is holding R2 and waiting for R1, P3
is waiting for R1 as well as R2.

The graph is deadlock free since no cycle is being formed in the graph.

Deadlock Detection using RAG


If a cycle is being formed in a Resource allocation graph where all the resources have the
single instance then the system is deadlocked.

In Case of Resource allocation graph with multi-instanced resource types, Cycle is a


necessary condition of deadlock but not the sufficient condition.

The following example contains three processes P1, P2, P3 and three resources R2, R2,
R3. All the resources are having single instances each.

If we analyze the graph then we can find out that there is a cycle formed in the graph since
the system is satisfying all the four conditions of deadlock.
Allocation Matrix
Allocation matrix can be formed by using the Resource allocation graph of a system. In
Allocation matrix, an entry will be made for each of the resource assigned. For Example,
in the following matrix, en entry is being made in front of P1 and below R3 since R3 is
assigned to P1.

Process R1 R2 R3

P1 0 0 1

P2 1 0 0

P3 0 1 0

Request Matrix
In request matrix, an entry will be made for each of the resource requested. As in the
following example, P1 needs R1 therefore an entry is being made in front of P1 and below
R1.

Process R1 R2 R3

P1 1 0 0

P2 0 1 0

P3 0 0 1

Avial = (0,0,0)
Neither we are having any resource available in the system nor a process going to release.
Each of the process needs at least single resource to complete therefore they will
continuously be holding each one of them.

We cannot fulfill the demand of at least one process using the available resources
therefore the system is deadlocked as determined earlier when we detected a cycle in the
graph.
Banker's Algorithm in Operating System
(OS)
It is a banker algorithm used to avoid deadlock and allocate resources safely to each
process in the computer system. The 'S-State' examines all possible tests or activities
before deciding whether the allocation should be allowed to each process. It also helps
the operating system to successfully share the resources between all the processes. The
banker's algorithm is named because it checks whether a person should be sanctioned a
loan amount or not to help the bank system safely simulate allocation resources. In this
section, we will learn the Banker's Algorithm in detail. Also, we will solve problems based
on the Banker's Algorithm. To understand the Banker's Algorithm first we will see a real
word example of it.

Suppose the number of account holders in a particular bank is 'n', and the total money in
a bank is 'T'. If an account holder applies for a loan; first, the bank subtracts the loan
amount from full cash and then estimates the cash difference is greater than T to approve
the loan amount. These steps are taken because if another person applies for a loan or
withdraws some amount from the bank, it helps the bank manage and operate all things
without any restriction in the functionality of the banking system.

Similarly, it works in an operating system. When a new process is created in a computer


system, the process must provide all types of information to the operating system like
upcoming processes, requests for their resources, counting them, and delays. Based on
these criteria, the operating system decides which process sequence should be executed
or waited so that no deadlock occurs in a system. Therefore, it is also known as deadlock
avoidance algorithm or deadlock detection in the operating system.

Advantages
Following are the essential characteristics of the Banker's algorithm:

1. It contains various resources that meet the requirements of each process.


2. Each process should provide information to the operating system for upcoming
resource requests, the number of resources, and how long the resources will be
held.
3. It helps the operating system manage and control process requests for each type
of resource in the computer system.
4. The algorithm has a Max resource attribute that represents indicates each process
can hold the maximum number of resources in a system.

Disadvantages
1. It requires a fixed number of processes, and no additional processes can be started
in the system while executing the process.
2. The algorithm does no longer allows the processes to exchange its maximum
needs while processing its tasks.
3. Each process has to know and state their maximum resource requirement in
advance for the system.
4. The number of resource requests can be granted in a finite time, but the time limit
for allocating the resources is one year.
When working with a banker's algorithm, it requests to know about three things:

1. How much each process can request for each resource in the system. It is denoted
by the [MAX] request.
2. How much each process is currently holding each resource in a system. It is
denoted by the [ALLOCATED] resource.
3. It represents the number of each resource currently available in the system. It is
denoted by the [AVAILABLE] resource.

Following are the important data structures terms applied in the banker's algorithm as
follows:

Suppose n is the number of processes, and m is the number of each type of resource
used in a computer system.

1. Available: It is an array of length 'm' that defines each type of resource available
in the system. When Available[j] = K, means that 'K' instances of Resources type
R[j] are available in the system.
2. Max: It is a [n x m] matrix that indicates each process P[i] can store the maximum
number of resources R[j] (each type) in a system.
3. Allocation: It is a matrix of m x n orders that indicates the type of resources
currently allocated to each process in the system. When Allocation [i, j] = K, it
means that process P[i] is currently allocated K instances of Resources type R[j] in
the system.
4. Need: It is an M x N matrix sequence representing the number of remaining
resources for each process. When the Need[i] [j] = k, then process P[i] may require
K more instances of resources type Rj to complete the assigned work.
Nedd[i][j] = Max[i][j] - Allocation[i][j].
5. Finish: It is the vector of the order m. It includes a Boolean value (true/false)
indicating whether the process has been allocated to the requested resources, and
all resources have been released after finishing its task.

The Banker's Algorithm is the combination of the safety algorithm and the resource
request algorithm to control the processes and avoid deadlock in a system:

Safety Algorithm
It is a safety algorithm used to check whether or not a system is in a safe state or follows
the safe sequence in a banker's algorithm:

1. There are two vectors Wok and Finish of length m and n in a safety algorithm.

Initialize: Work = Available


Finish[i] = false; for I = 0, 1, 2, 3, 4… n - 1.

2. Check the availability status for each type of resources [i], such as:

Need[i] <= Work


Finish[i] == false
If the i does not exist, go to step 4.
3. Work = Work +Allocation(i) // to get new resource allocation

Finish[i] = true

Go to step 2 to check the status of resource availability for the next process.

4. If Finish[i] == true; it means that the system is safe for all processes.

Resource Request Algorithm


A resource request algorithm checks how a system will behave when a process makes
each type of resource request in a system as a request matrix.

Let create a resource request array R[i] for each process P[i]. If the Resource Requesti [j]
equal to 'K', which means the process P[i] requires 'k' instances of Resources type R[j] in
the system.

1. When the number of requested resources of each type is less than


the Need resources, go to step 2 and if the condition fails, which means that the process
P[i] exceeds its maximum claim for the resource. As the expression suggests:

If Request(i) <= Need


Go to step 2;

2. And when the number of requested resources of each type is less than the available
resource for each process, go to step (3). As the expression suggests:

If Request(i) <= Available


Else Process P[i] must wait for the resource since it is not available for use.

3. When the requested resource is allocated to the process by changing state:

Available = Available - Request


Allocation(i) = Allocation(i) + Request (i)
Needi = Needi - Requesti

When the resource allocation state is safe, its resources are allocated to the process P(i).
And if the new state is unsafe, the Process P (i) has to wait for each type of Request R(i)
and restore the old resource-allocation state.

Example: Consider a system that contains five processes P1, P2, P3, P4, P5 and the
three resource types A, B and C. Following are the resources types: A has 10, B has 5
and the resource type C has 7 instances.

Process Allocation Max Available


A B C A B C A B C
P1 0 1 0 7 5 3 3 3 2

P2 2 0 0 3 2 2

P3 3 0 2 9 0 2

P4 2 1 1 2 2 2

P5 0 0 2 4 3 3

Answer the following questions using the banker's algorithm:

1. What is the reference of the need matrix?


2. Determine if the system is safe or not.
3. What will happen if the resource request (1, 0, 0) for process P1 can the system
accept this request immediately?

Ans. 2: Context of the need matrix is as follows:

Need [i] = Max [i] - Allocation [i]


Need for P1: (7, 5, 3) - (0, 1, 0) = 7, 4, 3
Need for P2: (3, 2, 2) - (2, 0, 0) = 1, 2, 2
Need for P3: (9, 0, 2) - (3, 0, 2) = 6, 0, 0
Need for P4: (2, 2, 2) - (2, 1, 1) = 0, 1, 1
Need for P5: (4, 3, 3) - (0, 0, 2) = 4, 3, 1

Process Need
A B C

P1 7 4 3

P2 1 2 2

P3 6 0 0

P4 0 1 1
P5 4 3 1

Hence, we created the context of need matrix.

Ans. 2: Apply the Banker's Algorithm:

Available Resources of A, B and C are 3, 3, and 2.

Now we check if each type of resource request is available for each process.

Step 1: For Process P1:

Need <= Available

7, 4, 3 <= 3, 3, 2 condition is false.

So, we examine another process, P2.

Step 2: For Process P2:

Need <= Available

1, 2, 2 <= 3, 3, 2 condition true

New available = available + Allocation

(3, 3, 2) + (2, 0, 0) => 5, 3, 2

Similarly, we examine another process P3.

Step 3: For Process P3:

P3 Need <= Available

6, 0, 0 < = 5, 3, 2 condition is false.

Similarly, we examine another process, P4.

Step 4: For Process P4:

P4 Need <= Available

0, 1, 1 <= 5, 3, 2 condition is true

New Available resource = Available + Allocation

5, 3, 2 + 2, 1, 1 => 7, 4, 3

Similarly, we examine another process P5.


Step 5: For Process P5:

P5 Need <= Available

4, 3, 1 <= 7, 4, 3 condition is true

New available resource = Available + Allocation

7, 4, 3 + 0, 0, 2 => 7, 4, 5

Now, we again examine each type of resource request for processes P1 and P3.

Step 6: For Process P1:

P1 Need <= Available

7, 4, 3 <= 7, 4, 5 condition is true

New Available Resource = Available + Allocation

7, 4, 5 + 0, 1, 0 => 7, 5, 5

So, we examine another process P2.

Step 7: For Process P3:

P3 Need <= Available

6, 0, 0 <= 7, 5, 5 condition is true

New Available Resource = Available + Allocation

7, 5, 5 + 3, 0, 2 => 10, 5, 7

Hence, we execute the banker's algorithm to find the safe state and the safe
sequence like P2, P4, P5, P1 and P3.

Ans. 3: For granting the Request (1, 0, 2), first we have to check that Request <=
Available, that is (1, 0, 2) <= (3, 3, 2), since the condition is true. So the process P1 gets
the request immediately.

You might also like