0% found this document useful (0 votes)
7 views

Atharv OSY MP Final

Uploaded by

moretv2006
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)
7 views

Atharv OSY MP Final

Uploaded by

moretv2006
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

A

Micro project report On

“ Banker’s algorithm for deadlock detection”

SUBMITTED TO M.S.B.T.E., Mumbai

For the Award of


DIPLOMA IN INFORMATION TECHNOLOGY
BY

Roll no Name of Student Enrollment no


40 Atharv Suresh Chavan 2210740201
41 Tejas Vilas More 2210740202

UNDER THE GUIDANCE OF

Mrs.Wangikar V.S
DEPARTMENT OF INFORMATION TECHNOLOGY
NBA ACCREDIATED

SVERI’s College of Engineering (Polytechnic), Pandharpur


Gopalpur Pandharpur-41330
2024-25

AFFILIATED TO

M.S.B.T.E.
Evolution sheet for Micro Project

Academic Year:- 2024-25 Name of Faculty:-Mrs.Wangikar V.S


Course:- Computer Engineering Course code:- CO5I
Subject:-Operating System Subject Code:- 22032
Semester:- V Scheme:- I

Title of Project:- Banker’s algorithm for deadlock detection

COs addressed by the Micro Project:

Generate business ideas(product/service)for intrapreneurial


Co4
And Entrepreneurial opportunities through brainstorming.
Comments/Suggestions about team work/leadership/inter-personal communication (if any)

Marks out of 4
Marks out of 6 Total
for
for mars
Roll No Name of students performance
performance in out
in oral/
group activity of 10
Presentation

40 Atharv Suresh Chavan


41 Tejas Vilas More

Name and Mrs.Wangikar V.S


Signature of
faculty
SVERI’s COLLEGE OF ENGINEERING (POLYTECHNIC), PANDHARPUR.

CERTIFICATE

There is to certify that the Project report entitled

“ Banker’s algorithm for deadlock detection”


Submitted by

Roll no Name of Student Enrollment no


40 Atharv Suresh Chavan 2210740201
41 Tejas Vilas More 2210740202

is a bonafide work carried out by above students, under the guidance of Mrs.Wangikar V.S and it is
submitted towards the fulfillment of requirement of MSBTE, Mumbai for the award of Diploma in
Information Technology at SVERI’s COE (Polytechnic), Pandharpur during the academic year 2024-25.

(Mrs.Wangikar V.S)
Guide
(Mr. Bhandare P.S ) (Dr. Misal N. D.)
HOD Principal

Place: Pandharpur

Date:
`

Acknowledgement

“ Banker’s algorithm for deadlock detection” has been developed successfully with a
great contribution of four students in a period of two months. We like to appreciate their guidance,
encouragement and willingness since without their support the project would not have been a success.
We would like to give our heartfelt gratitude to Principal Dr. N.D. Misal Sir ,Guide Mrs.Wangikar V.S
Mam & HOD Mr. P. S. Bhandare Sir who is the supervisor of our project for helping and encouraging
us in many ways to make our project a success. We would never been able to finish our work without
great support and enthusiasm from friends and support from our family. We would like to thank the
department of Computer Engineering, for giving us permission to initiate this project and successfully
finishit.
`

Introduction

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

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

Course outcome addressed:-

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

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.

Resources used:-

Sr Name of Resource material Specification Quantit


No y

1. Computer System 4 GB RAM, 1


Windows 8.1 OS

2. Internet Youtube / Wikipedia -

3. textbook/manual OSY Operating Systems 22516 -


`

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

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


`

Banker’s Algorithm Example Solutions:-


Assume we have nine tape drives. Consider whether or not the following states are safe or unsafe

State Current Maximum Need


Loan
Process 0 3
A
Process 3 5
B

Process 4 7
C

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 5 7
A

Process 2 5
B
Process 1 3
C

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

Suppose that Process C requests one tape drive.


If this request is granted, will we still be in a safe state?

State Current Maximum Need


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

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

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("\nEnternumberofresources:");scanf("%d"&resources);

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("\nTheClaimResourceis:");

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++)

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++)

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;

}
`

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;

}
`

Output:-

Outputs of the Micro-Project:-

We got detailed information about CPU scheduling & algorithms, also the deadlock situation which
has four necessary conditions
`

· Mutual Exclusion
· Hold & Wait
· No-Preemption
· 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.
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:-

❖ How much each process can request for each resource in the system. It is denoted by the [MAX]
request.
`

❖ How much each process is currently holding each resource in a system. It is denoted by the
[ALLOCATED] resource.
❖ It represents the number of each resource currently available in the system. It is denoted by the
[AVAILABLE] resource.

Outcomes of this Micro-Project:-


 Increase knowledge about Banker’s & Safety algorithm for deadlock detection and avoidance.
 Experience teamwork.
 Increase communication skill
 Know about Banker’s & Safety algorithm for deadlock detection and avoidance
`

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

References:-

1. Textbook/manual
2. https://www.techtarget.com

You might also like