Professional Documents
Culture Documents
THIM TRUST’S
A
PROJECT REPORT
ON
“Banker’s algorithm”
IN THE FULFILMENT OF
DIPLOMA
IN
Computer Engineering
Year 2022-23
SUBMITED BY
PROJECT GUIDE
Prof. Rosy Bhoi
1
H. J. THIM TRUST’S
Boisar chillar Road, Boisar (E), Tal. Palghar Dist. Palghar, Pin- 401501
Certificate
This is to certify that the report has been submitted by following students
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
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.
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.
4
TABLE OF CONTENT
SR.
TITLE PAGE NO
NO
1. Introduction 6
4. Examples: 10,11,12&13
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.
1. Available:
2. Max :
It is a 2-d array of size ‘n*m’ that defines the maximum demand of each
process in a system.
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.
4. Need :
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
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.
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:
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:
Disadvantages:
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