Banker's Algorithm For Deadlock Detection: Sr. No Roll No (Sem 5) Full Name of Student Enrolment No 1 2 3 4 5
Banker's Algorithm For Deadlock Detection: Sr. No Roll No (Sem 5) Full Name of Student Enrolment No 1 2 3 4 5
A STUDY ON
“ Banker’s algorithm for deadlock detection ”
Submitted in 2022-2023 by the group of 5 Students
1
CERTIFICATE
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION, MUMBAI
Roll No: ……. Of Fifth Semester of Computer Engineering Diploma in Engineering &
Technology at 1432 GOVERNMENT POLYTECHNIC, NANDURBAR, has completed the
Micro Project satisfactorily in Subject OSY in the academic year 2022-2023 as per the
MSBTE prescribed curriculum of I Scheme.
2
INDEX
1 First Page 1
2 Certificate 2
3 Index 3
4 Annexure –IA(Part A) 4
3 Brief Introduction 6
4 Literature Review 7
12 References 19
14 Annexure part-2 21
3
Annexure – A
Title of Micro-Project
4
2.0 Course outcome addressed.
Apply deadlock avoidance and safety algorithms to detect and avoid deadlocks.
We will concentrate on the materials we require, as well as the instructions, and sort
it out in a manner that will expedite the various duties of the team members.
Get details about the algorithms and how they are used to detect and avoid deadlock.
Solve the problems (examples) based on algorithms to detect and avoid deadlock.
Cross-check all the conclusions and answers.
Prepare a report on the topic.
2. Internet Youtube /
Wikipedia
5
2.0 Brief Introduction/Rationale
In an operating system, the CPU plays a more important role in executing processes and
controlling the flow of the computing smoothly. Deadlocks are the main problems for
the operating system to tackle, whenever a deadlock occurs execution of processes
stops completely. To overcome (Solve) this deadlock situation there are two algorithms
one for avoidance and one for detection. In the further report, we are going to see take
look at how they are implemented with the help of examples.
6
2.1 Literature Review
Deadlock is not the main hazard to the operating system. o Deadlocks don’t arise more
often, the frequency of deadlock occurrence is too less but whenever a deadlock occurs
system’s execution stops completely. Most systems don’t involve default codes for
deadlock avoidance and detection in the system because of deadlock’s rare occurrence
and putting complex codes for deadlock avoidance and detection does not significantly
impact the speed of computing. To overcome this situation we can use banker’s &
Safety algorithms
We focused on the materials we needed, as well as the instructions, and sorted it out
in a manner that will expedite different responsibilities of the team members.
The gathered information about the algorithms and how they are used to detect and
avoid deadlock.
Prepared a report.
7
Banker’s Algorithm Example Solutions
Assume we have nine tape drives. Consider whether or not the following states
are safe or unsafe
State Current Loan Maximum Need
Process A 0 3
Process B 3 5
Process C 4 7
Since only 7 (3+4) tape drives are currently on loan (allocated), two (2) tape drives are
still available.
Process B can finish with only two additional tape drives.
Once Process B is done, it will release all 5 tape drives, making the number of available
tape drives = 5.
With only three of these tape drives, either Process A or Process C may complete and
release its tape drives.
This means that there are two possible safe sequences: <Process B, Process A, Process
C> and <Process B, Process C, Process A>.
Thus, we say that this is a safe state.
Again assume we have nine tape drives. Consider whether or not the following states
are safe or unsafe.
Since 8 (5+2+1) tape drives are currently on loan (allocated), only one tape drive is still
available.
None of the three processes can complete with only one additional tape drive.
This means that there are no safe sequences possible.
Thus, we say that this is an unsafe state.
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.
9
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.
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.
10
Banker Algorithm code in C
#include <iostream>
#include <stdio.h>
int Resources_Available[5];
int Resources_Required[5][5];
int Resources_Already_Having[5][5];
int main()
scanf("%d", &processes);
running[i] = 1;
counter++;
scanf("%d", &resources);
11
printf("\nEnter Claim Resources:");
scanf("%d", &maxres[i]);
scanf("%d", &Resources_Already_Having[i][j]);
scanf("%d", &Resources_Required[i][j]);
printf("\t%d", maxres[i]);
printf("\t%d", Resources_Already_Having[i][j]);
printf("\n");
printf("\t%d", Resources_Required[i][j]);
printf("\n");
allocation[j] += Resources_Already_Having[i][j];
printf("\nAllocated resources:");
printf("\t%d", allocation[i]);
printf("\nAvailable resources:");
printf("\t%d", Resources_Available[i]);
printf("\n");
while (counter != 0)
safe = 0;
{
14
if (running[i])
Exection = 1;
Exection = 0;
break;
if (Exection)
running[i] = 0;
counter--;
safe = 1;
Resources_Available[j] += Resources_Already_Having[i][j];
break;
}
15
}
if (!safe)
break;
else
printf("\nAvailable Resources:");
printf("\t%d", Resources_Available[i]);
printf("\n");
return 0;
16
4.0 Outputs of the Micro-Project
We got detailed information about CPU scheduling & algorithms, also the deadlock
situation which has four necessary conditions
1. Mutual Exclusion
2. Hold & Wait
3. No-Preemption
4. Circular Wait (if that all conditions hold simultaneously )
in the system then a 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 the second one is deadlock detection. We also focused on other techniques of
handling deadlocks
Advantages:-
1. It contains various resources that meet the requirements of each process.
17
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:-
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.
18
5.0 Skill Developed / Learning outcomes of this Micro-Project
1. Increase knowledge about Banker’s & Safety algorithm for deadlock detection
and avoidance.
2. Experience teamwork.
3. Increase communication skill
4. Know about Banker’s & Safety algorithm for deadlock detection and
avoidance
6.0 Conclusion
The banker's algorithm is a resource allocation and deadlock avoidance algorithm that
tests for safety by simulating the allocation for predetermined maximum possible
amounts of all resources, then makes an “s-state” check to test for possible activities,
before deciding whether allocation should be allowed to continue the process.
6.1 References
1. Textbook/manual
2. https://www.techtarget.com
19
Weekly Work / Progress Report
Timing
Week Work or activity Performed Sign of the
No. Date From To Duration Guide
in hours
Discussion and Finalization of the Project
1 16/10/22 2:00 3:00 1 Title
20
ANNEXURE – II
Evaluation Sheet for the micro project(Teachers copy)
Academic Year:- 2022-2023 Name of Faculty :- Mr. M.M.Goswami
Sem :- Fifth Program Name and Code :- Computer Engineering.
Course :- OSY Course Code :- 22516
1) Daksh Malve
Name of Students:- 2) Harshal Patil
3) Vaishnavi Bhavsar
4) Ketan Bhoi
5) Siddhi Wagh
Title of the Project :- Banker’s & Safety algorithm for deadlock detection
( )
Signature With Name and Designation of the Faculty Member
21