You are on page 1of 15

H. J.

THIM TRUST’S

THEEM COLLEGE OF ENGINEERING

A
PROJECT REPORT
ON

“Banker’s algorithm”
IN THE FULFILMENT OF
DIPLOMA
IN
Computer Engineering

Year 2022-23

SUBMITED BY

1. Sankhe Neha Vinod 01


2. Bhimani Insha Husen 10
3. Bhide Priyanka Milind 13
4. Patil Sanj Pankaj

PROJECT GUIDE
Prof. Rosy Bhoi

1
H. J. THIM TRUST’S

THEEM COLLEGE OF ENGINEERING

Boisar chillar Road, Boisar (E), Tal. Palghar Dist. Palghar, Pin- 401501

Academic Year 2022-23

Certificate
This is to certify that the report has been submitted by following students

1. Sankhe Neha Vinod


2. Bhimani Insha Husen
3. Bhide Priyanka Milind
4. Patil Sanj Pankaj

This project work has been completed by 3rd Year Students of course Computer Department as a
Part of Team Work Prescribed by Maharashtra State Board of Technical Education, Mumbai. We
have guided and assisted the Students for the above work, which has been found
Satisfactory/Good/Very Good.

Signature of Signature of

(Prof. Rosy Bhoi) (Prof. Ahmed Shaikh)


Teacher/Guide H.O.D.
Signature of
(Prof. Sayyad L.B.)
Principal

2
DECLARATION

We students of second year diploma in Computer engineering, hereby declare that we have
successfully completed this project on Banker’s Algorithm in academic year 2022-23 in
semester fifth. The information incorporated in this project is true and original to best of our
knowledge.

1. Sankhe Neha Vinod

2. Bhimani Insha Husen

3. Bhide Priyanka Milind

4. Patil Sanj Pankaj

Date:

3
ACKNOWLEDGEMENT

It’s our pleasure to take this opportunity to thank with deep sense of gratitude to our guide,
staff members of Third year department & everyone who have directly or indirectly contributed
tour project as a success. With immense pleasure we express our deep sense of gratitude & vote of
thank to our project guide Prof. Rosy Bhoi for her constant interest, motivation & valuable
guidance during work & completion of this project report.

We are also very thankful to all those who supported us without which project would not
have been completed successfully.

1. Sankhe Neha Vinod

2. Bhimani Insha Husen

3. Bhide Priyanka Milind

4. Patil Sanj Pankaj

4
TABLE OF CONTENT

SR.
TITLE PAGE NO
NO

1. Introduction 6

1. Why banker’s algorithm is named so?


2. 2. Following data structure are used to 7&8
implement the banker’s algorithm
1. The algorithm for finding out whether
3. or not a system is in a safe state can be 9
described as follow:
2. Resource request algorithm

4. Examples: 10,11,12&13

5. Advantages and Disadvantages 14

6. conclusion 15

5
INTRODUCTION
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.

6
 Why Banker’s algorithm is named so?
Banker’s algorithm is named so because it is used in banking system to
check whether loan can be sanctioned to a person or not. Suppose there are
n number of account holders in a bank and the total sum of their money is S.
If a person applies for a loan then the bank first subtracts the loan amount
from the total money that bank has and if the remaining amount is greater
than S then only the loan is sanctioned. It is done because if all the account
holders comes to withdraw their money then the bank can easily do it.

In other words, the bank would never allocate its money in such a way
that it can no longer satisfy the needs of all its customers. The bank would
try to be in safe state always.

 Following Data structures are used to implement the Banker’s


Algorithm:
Let ‘n’ be the number of processes in the system and ‘m’ be the number of
resources types.

1. Available:

 It is a 1-d array of size ‘m’ indicating the number of available resources


of each type.

 Available[ j ] = k means there are ‘k’ instances of resource type Rj.

2. Max :

 It is a 2-d array of size ‘n*m’ that defines the maximum demand of each
process in a system.

 Max [i, j] = k means process Pi may request at most ‘k’ instances of


resource type Rj.

7
3. Allocation :

 It is a 2-d array of size ‘n*m’ that defines the number of resources of each
type currently allocated to each process.

 Allocation[ i, j ] = k means process Pi is currently allocated ‘k’ instances


of resource type Rj

4. Need :

 It is a 2-d array of size ‘n*m’ that indicates the remaining resource


need of each process.

 Need [ i, j ] = k means process Pi currently need ‘k’ instances of


resource type Rj

 Need [ i, j ] = Max [ i, j ] – Allocation [ i, j ]

Allocationi specifies the resources currently allocated to process Pi and


Needi specifies the additional resources that process Pi may still request to
complete its task.

Banker’s algorithm consists of Safety algorithm and Resource request


algorithm Safety Algorithm.

8
 The algorithm for finding out whether or not a system is in a safe state can
be described as follows:

1. Let Work and Finish be vectors of length ‘m’ and ‘n’ respectively.
Initialize: Work = Available
Finish[i] = false; for i=1, 2, 3, 4….n

2. Find an i such that both


a) Finish[i] = false
b) Needi <= Work
if no such i exists goto step (4)

3. Work = Work + Allocation[i]


Finish[i] = true
goto step (2)

4. if Finish [i] = true for all i


then the system is in a safe state .

 Resource-Request Algorithm:
Let Requesti be the request array for process Pi. Requesti [j] = k means
process Pi wants k instances of resource type Rj. When a request for resources is
made by process Pi, the following actions are taken:
1. If Requesti <= Needi
Goto step (2) ; otherwise, raise an error condition, since the process has exceeded
its maximum claim.

2. If Requesti <= Available


Goto step (3); otherwise, Pi must wait, since the resources are not available.

3. Have the system pretend to have allocated the requested resources to process
Pi by modifying the state as
follows:
Available = Available – Requesti
Allocationi = Allocationi + Requesti
Needi = Needi– Requesti

9
 Example:

Considering a system with five processes P0 through P4 and three resources


of type A, B, C. Resource type A has 10 instances, B has 5 instances and type
C has 7 instances. Suppose at time t0 following snapshot of the system has been
taken:

Question1. What will be the content of the Need matrix?


Need [i, j] = Max [i, j] – Allocation [i, j]
So, the content of Need Matrix is:

10
Question2. Is the system in a safe state? If Yes, then what is the
safe sequence?
Applying the Safety algorithm on the given system,

11
Question3. What will happen if process P1 requests one additional
instance of resource type A and two instances of resource type C?

12
We must determine whether this new system state is safe. To do so, we again
execute Safety algorithm on the above data structures.

Hence the new system state is safe, so we can immediately grant the request for
process P1.

13
 Advantages:

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.

14
Conclusion

We got detail information about CPU scheduling & algorithms, also the
deadlock situation which is has four necessary conditions (1.Mutual Exclusion
2.Hold & Wait 3.No-Preemption 4.Circular Wait) if that all conditions hold
simultaneously in system then deadlock situation can occur in the system. There are
four ways we can face the deadlock out of four we saw two methods one is deadlock
avoidance and second one is deadlock detection. We also focused ourselves on other
techniques of handling deadlocks.
There comes a situation of deadlock in OS in which a set of processes is
blocked because it is holding a resource and also requires some other resources at
the same time that are being acquired by other processes. Bankers algorithm in
Operating System is used to avoid such deadlocks and also, for resource allocation
safely to each process in the system. There are some important data structure terms
that are used to implement Bankers algorithm in OS and they are as follows:
Available, Max, Allocation, Need and Finish. Bankers algorithm consists of two
main algorithms used to avoid deadlock and control the processes within the system:
Safety algorithm and Resource request algorithm.
Safety algorithm in OS is used to mainly check whether the system is in a safe
state or not. Resource request algorithm checks the behavior of a system whenever
a particular process makes a resource request in a system. It mainly checks whether
resource requests can be safely granted or not within the system.

15

You might also like