0% found this document useful (0 votes)
587 views21 pages

Banker's Algorithm For Deadlock Detection: Sr. No Roll No (Sem 5) Full Name of Student Enrolment No 1 2 3 4 5

This document outlines a study conducted by 5 students on the topic of "Banker's algorithm for deadlock detection" under the guidance of their professor Mr. M.M. Goswami at Government Polytechnic in Nandurbar, Maharashtra, India. It includes an introduction to the topic, literature review, methodology, examples and explanations of Banker's algorithm, a C program for implementing the algorithm, outputs, advantages and disadvantages, learning outcomes, and references.

Uploaded by

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

Banker's Algorithm For Deadlock Detection: Sr. No Roll No (Sem 5) Full Name of Student Enrolment No 1 2 3 4 5

This document outlines a study conducted by 5 students on the topic of "Banker's algorithm for deadlock detection" under the guidance of their professor Mr. M.M. Goswami at Government Polytechnic in Nandurbar, Maharashtra, India. It includes an introduction to the topic, literature review, methodology, examples and explanations of Banker's algorithm, a C program for implementing the algorithm, outputs, advantages and disadvantages, learning outcomes, and references.

Uploaded by

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

Project Name:- Banker’s algorithm for deadlock detection Academic Year: 2022-2023

Subject Name: - Operating System Semester: - Fifth

A STUDY ON
“ Banker’s algorithm for deadlock detection ”
Submitted in 2022-2023 by the group of 5 Students

Sr. No Roll No Full Name of Student Enrolment No


(Sem 5)
1 3142 Daksh Malve 2014320116
2 3153 Harshal Patil 2014320200
3 3146 Vaishnavi Bhavsar 2014320120
4 3131 Ketan Bhoi 2014320101
5 3138 Siddhi Wagh 2014320112

Under the Guidance of


Mr. M.M.Goswami sir
In

Three Year Diploma in Engineering & Technology of Maharashtra State Bord of


Technical Education, Mumbai (Autonomous)
ISO 9001:2008 (ISO/IEC-27001-2013)
At

1432 GOVERMENT POLYTECHNIC, NANDURBAR.

1
CERTIFICATE
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION, MUMBAI

This is to certify that Mr/Mrs. 1) Daksh Malve (Roll NO: 3142)


2) Harshal Patil (Roll NO: 3153)
3) Vaishnavi Bhavsar (Roll NO: 3146)
4) Ketan Bhoi (Roll NO: 3131)
5) Siddhi Wagh (Roll NO: 3138)

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.

Place : Nandurbar Enrolment No: 1) 2014320116


2) 2014320200
3) 2014320120
4) 2014320101
5) 2014320112
Date :

Project Guide Head of the Department Principal


Mr .M.M.Goswami Mr. Sanjay.B.Thakre Dr.S.D.Pabhle

2
INDEX

SR.NO. CONTENTS Page No

1 First Page 1

2 Certificate 2

3 Index 3

4 Annexure –IA(Part A) 4

5 Course Outcomes Addressed 5

1 Proposed Methodology Followed 5

2 Actual Resources Used 5

3 Brief Introduction 6

4 Literature Review 7

5 Actual Methodology Followed 7

6 Banker’s Algorithm Examples 8,9,10

7 C program for Banker’s algorithm 11 to 16


8 Outputs of the Micro–project 17

9 Advantages & Disadvantages 17,18

10 Skill Developed / Learning Outcomes from this Micro–project 19


11 Conclusion 19

12 References 19

13 Action Plan ( Weekely Work & Progress Report) 20

14 Annexure part-2 21

3
Annexure – A
Title of Micro-Project

" Banker’s algorithm for deadlock detection and avoidance "

1.0   Aims/Benefits of the micro project

An Operating System is basically a system program that controls the


execution of application programs and acts as an interface between applications and
the computer hardware. It manages the computer system resources to be used in an
efficient manner.
This course enables one to learn the internal functioning of operating systems and
will help in identifying appropriate Operating Systems for given applications/tasks. This
course is also a prerequisite for the group of courses included in the 'Cloud
Infrastructure Maintenance' Elective group.

4
2.0   Course outcome addressed.

 Apply deadlock avoidance and safety algorithms to detect and avoid deadlocks.

3.0 Proposed methodology

 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.

4.0 Resources used

Sr No Name of Specification Quantity


Resource material

1. Computer System 4 GB RAM, 1


Windows 8.1 OS

2. Internet Youtube /
Wikipedia 

3. textbook/manual OSY Operating


Systems 22516

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 

3.0 Actual Methodology Followed 

 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. 

 Solved examples to better understand Algorithms and their methods. 

 Cross-checked outputs and answers. 

 Prepared a report. 

 Checked for any further changes to be done in the project. 

 Created the final report of the project. 

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.

State     Current Loan   Maximum Need


Process A                 5        7
Process B                 2        5
Process C                 1        3

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.

Now return to the first example.


8
Suppose that Process C requests one tape drive.
If this request is granted, will we still be in a safe state?

State     Current Loan   Maximum Need


Process A         0        3
Process B         3        5
Process C         5        7

The number of available tape drives is reduced to one (1).


No process can be granted enough tape drives to complete.
This means that there will be no safe sequences possible, if we grant Process C's
request.
Thus, granting this request will take us from a safe state to an unsafe state.

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

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 allocation[5] = {0, 0, 0, 0, 0};

int maxres[5], running[5], safe = 0;

int counter = 0, i, j, Exection, resources, processes, k = 1;

int main()

printf("\nEnter number of processes: ");

scanf("%d", &processes);

for (i = 0; i < processes; i++)

running[i] = 1;

counter++;

printf("\nEnter number of resources: ");

scanf("%d", &resources);
11
printf("\nEnter Claim Resources:");

for (i = 0; i < resources; i++)

scanf("%d", &maxres[i]);

printf("\nEnter Allocated Resource Table:\n");

for (i = 0; i < processes; i++)

for(j = 0; j < resources; j++)

scanf("%d", &Resources_Already_Having[i][j]);

printf("\nEnter Maximum Claim Table:\n");

for (i = 0; i < processes; i++)

for(j = 0; j < resources; j++)

scanf("%d", &Resources_Required[i][j]);

printf("\nThe Claim Resources is: ");


12
for (i = 0; i < resources; i++)

printf("\t%d", maxres[i]);

printf("\nThe Allocated Resource Table:\n");

for (i = 0; i < processes; i++)

for (j = 0; j < resources; j++)

printf("\t%d", Resources_Already_Having[i][j]);

printf("\n");

printf("\nThe Maximum Claim Table:\n");

for (i = 0; i < processes; i++)

for (j = 0; j < resources; j++)

printf("\t%d", Resources_Required[i][j]);

printf("\n");

for (i = 0; i < processes; i++)

for (j = 0; j < resources; j++)


13
{

allocation[j] += Resources_Already_Having[i][j];

printf("\nAllocated resources:");

for (i = 0; i < resources; i++)

printf("\t%d", allocation[i]);

for (i = 0; i < resources; i++)

Resources_Available[i] = maxres[i] - allocation[i];

printf("\nAvailable resources:");

for (i = 0; i < resources; i++)

printf("\t%d", Resources_Available[i]);

printf("\n");

while (counter != 0)

safe = 0;

for (i = 0; i < processes; i++)

{
14
if (running[i])

Exection = 1;

for (j = 0; j < resources; j++)

if (Resources_Required[i][j] - Resources_Already_Having[i][j] > Resources_Available[j])

Exection = 0;

break;

if (Exection)

printf("\nProcess%d is Execting\n", i + 1);

running[i] = 0;

counter--;

safe = 1;

for (j = 0; j < resources; j++

Resources_Available[j] += Resources_Already_Having[i][j];

break;

}
15
}

if (!safe)

printf("\nThe processes are in unsafe state.\n");

break;

else

printf("\nThe process is in safe state");

printf("\nAvailable Resources:");

for (i = 0; i < resources; i++

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:-

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.

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

Details of 16 Engagement Hours of the Student


Regarding Completion of the Project

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

2 17/10/22 2:00 3:00 1 Preparation and Submission of Abstracts

3 23/10/22 3:00 4:00 1 Literature Review

4 24/10/22 2:00 3:00 1 Collection of Data

5 30/10/22 3:00 4:00 1 Sorting of Data

6 31/10/22 4:00 5:00 1 Discussion and Outline of Content

7 6/11/22 4:00 5:00 1 Rough Writing of the Projects Contents

Editing and Proof Reading of the Contents


8 7/11/22 2:00 3:00 1

9 13/11/22 2:00 3:00 1 Final Completion of the Project

Seminar Presentation, viva-vice,


10 3:00 4:00 1 Assessment and Submission of Report

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

• COs addressed by the Micro Project:


Major Learning Outcomes achieved by students by doing the Project:
(a)Practical Outcomes:
1. Basic knowledge
2. Discipline knowledge
3. Experiments and Practice
(b) Outcomes (in Cognitive domain)
1. Processing information
2. Constructing
3. Understanding
4. Applying knowledge

 Comment/Suggestions about team work/leadership


Marks out of 6 Marks out of 4 for Total
Roll No Student Name for performance in out
Performance in oral /
group activity presentation
of
10
3142 Daksh Malve
3153 Harshal Patil
3146 Vaishnavi Bhavsar
3131 Ketan Bhoi
3138 Siddhi Wagh

( )
Signature With Name and Designation of the Faculty Member

21

You might also like