Operating system LAB Report
Suman Educational Trust’s
Dilkap Research Institute of Engineering and Management Studies
A MINI PROJECT REPORT
ON
“Banker’s Algorithm ”
Submitted By
KRISHNA GUPTA (11)
OMKAR PARAB (22)
Second Year Engineering (Sem-IV)
Department of Computer Engineering
Dilkap Research Institute of Engineering and Management Studies
Campus: Village Mamdapur, post- Neral, Tal: Karjat, Pin- 410101
University of Mumbai
2018-2019
Page | 1
Operating system LAB Report
Suman Educational Trust’s
Dilkap Research Institute of Engineering and Management Studies
Department of Computer Engineering
Academic year 2018-19
CERTIFICATE
This is to certify that
KRISHNA GUPTA (11)
OMKAR PARAB (22)
From S.E Computer,
Have satisfactorily completed the requirements of the OSTL Mini Project entitled
“Banker’s Algorithm ”
As prescribed by the University of Mumbai Under the guidance of
Prof. Kalidas Bhawale
Prof. Kalidas Bhawale Prof. Indira Joshi
(Project Guide) (H.O.D)
Page | 2
Operating system LAB Report
ACKNOWLEDGEMENT
We would like to express our gratitude and appreciation to all those who gave us the possibility
to complete this project and this report. I and my team thank our head of department Prof. Indira
Joshi for giving us the accessory environment to acquire knowledge and skill. A special thanks to
Mr. Kalidas Bhawale, whose help, stimulating suggestions and encouragement, helped us to
coordinate our project especially in writing this report.
We would also like to acknowledge with much appreciation the crucial role of the staff of
Computer Laboratory, who gave the permission to use all required machinery and the necessary
material to complete the report special thanks goes to our friends, who gave suggestions about
the source code.
Page | 3
Operating system LAB Report
CONTENTS
CHAPTER NO. TITLE PAGE NO.
01 THEORY 5-7
02 PROGRAM 8-10
03 RESULTS 11-13
04 CONCLUSION 14
05 REFERENCES 15
Page | 4
Operating system LAB Report
CHAPTER 1
THEORY:BANKER’S ALOGORITHM
• Banker’s Algorithm is used to determine whether a process’s
request for allocation of resources be safely granted immediately.
• The grant of request be deferred to a later stage.
• For the banker’s algorithm to operate, each process has to a priori
specify its maximum requirement of resources.
• A process is admitted for execution only if its maximum
requirement of resources is within the system capacity of
resources.
• The Banker’s algorithm is an example of resource allocation policy
that avoids deadlock.
The resource allocation graph is not applicable to a resource
allocation system with multiple instances of each type. The deadlock-
avoidance algorithm that we describe next is applicable to such a system
but is less efficient than the resource-allocation graph scheme. This
algorithm is commonly known as the banker’s algorithm. The name was
chosen because the algorithm could be used in a banking system to
ensure that the bank never allocated its available cash in such a way that
it could no longer satisfy the needs of all its customers.
Page | 5
Operating system LAB Report
Fig: An unsafe state in a resource-allocation graph
When a new process enters the system, it must declare the maximum
number of instances of each resource type that it may need. This number
may not exceed the total number of resources in the system. When a user
requests a set of resources, the system must determine whether the
allocation of these resources will leave the system in a safe state. If it
will the resources are allocated; otherwise, the process must wait until
some other process releases enough resources.
Several data structures must be maintained to implement the banker’s
algorithm. These data structures encode the state of the resource-
allocation system. We need the following data structures, where n is the
number of processes in the system and m is the number of resource
types:
o AvailableA vector of length m indicates the number of available
resources of each type. If Available[j] equals k, then process Pi
may request atmost k instances of resource type Rj are available.
Page | 6
Operating system LAB Report
o MaxAn n x m matrix defines the maximum demand of each
process. If Max[i][j] equals k, then process Pi may request atmost
k instances of resource type Rj.
o AllocationAn n x m matrix defines the number of resources of
each type currently allocated to each process. If Allocation[i][j]
equals k,then process Pi is currently allocated k instances of
resource type Rj.
o NeedAn n x m matrix indicates the remaining resource need of
each process. If Need[i][j] equals k, then process Pi may need k
more instances of resource type Rj to complete its task. Note that
Need[i][j] equals Max[i][j]-Allocation[i][j].
Page | 7
Operating system LAB Report
CHAPTER 2
PROGRAM
#include <stdio.h>
#include <stdlib.h>
int main()
{
int Max[10][10], need[10][10], alloc[10][10], avail[10], completed[10],
safeSequence[10];
int p, r, i, j, process, count;
count = 0;
printf("Enter the no of processes : ");
scanf("%d", &p);
for(i = 0; i< p; i++)
completed[i] = 0;
printf("\n\nEnter the no of resources : ");
scanf("%d", &r);
printf("\n\nEnter the Max Matrix for each process : ");
for(i = 0; i < p; i++)
{
printf("\nFor process %d : ", i + 1);
for(j = 0; j < r; j++)
scanf("%d", &Max[i][j]);
}
printf("\n\nEnter the allocation for each process : ");
for(i = 0; i < p; i++)
{
printf("\nFor process %d : ",i + 1);
for(j = 0; j < r; j++)
scanf("%d", &alloc[i][j]);
}
printf("\n\nEnter the Available Resources : ");
Page | 8
Operating system LAB Report
for(i = 0; i < r; i++)
scanf("%d", &avail[i]);
for(i = 0; i < p; i++)
for(j = 0; j < r; j++)
need[i][j] = Max[i][j] - alloc[i][j];
do
{
printf("\n Max matrix:\tAllocation matrix:\n");
for(i = 0; i < p; i++)
{
for( j = 0; j < r; j++)
printf("%d ", Max[i][j]);
printf("\t\t");
for( j = 0; j < r; j++)
printf("%d ", alloc[i][j]);
printf("\n");
}
process = -1;
for(i = 0; i < p; i++)
{
if(completed[i] == 0)//if not completed
{
process = i ;
for(j = 0; j < r; j++)
{
if(avail[j] < need[i][j])
{
process = -1;
break;
}
}
}
if(process != -1)
break;
Page | 9
Operating system LAB Report
if(process != -1)
{
printf("\nProcess %d runs to completion!", process + 1);
safeSequence[count] = process + 1;
count++;
for(j = 0; j < r; j++)
{
avail[j] += alloc[process][j];
alloc[process][j] = 0;
Max[process][j] = 0;
completed[process] = 1;
}
}
}
while(count != p && process != -1);
if(count == p)
{
printf("\nThe system is in a safe state!!\n");
printf("Safe Sequence : < ");
for( i = 0; i < p; i++)
printf("%d ", safeSequence[i]);
printf(">\n");
}
else
printf("\nThe system is in an unsafe state!!");
Page | 10
Operating system LAB Report
CHAPTER 4
OUTPUT
Page | 11
Operating system LAB Report
Page | 12
Operating system LAB Report
Page | 13
Operating system LAB Report
CHAPTER 5
CONCLUSION
We have successfully execute the program .The things we required
“TURBO C AND INTERNET (For reference purpose only)”.It was a
great experience to design and implement the Banker’s Algorithm.
While working on this project , I have learned many things especially
how to apply the concept of c language while making chat room. In
this project we have used the basics of c language while making
banker’s algorithm . This project helped me to get the better
understanding to develop algo of Banker’s Algorithm. After doing
this project, I am Position to explain Banker’s Algorithm mini
project.
Page | 14
Operating system LAB Report
CHAPTER 7
REFERENCES
www.google.com
www.wikipedia.com
LIBRARY BOOKS
Page | 15