0% found this document useful (0 votes)
17 views4 pages

Exp 7 (Bankers Algo) - A - 05 - Leander Braganza

The document outlines Experiment 7 focused on the Banker's Algorithm, aimed at demonstrating deadlock avoidance in resource allocation systems. It includes theoretical explanations, algorithm details, and a program code example for implementing the algorithm. The experiment concludes with a successful execution of the algorithm and provides references for further reading.

Uploaded by

Ria Dcosta-036
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)
17 views4 pages

Exp 7 (Bankers Algo) - A - 05 - Leander Braganza

The document outlines Experiment 7 focused on the Banker's Algorithm, aimed at demonstrating deadlock avoidance in resource allocation systems. It includes theoretical explanations, algorithm details, and a program code example for implementing the algorithm. The experiment concludes with a successful execution of the algorithm and provides references for further reading.

Uploaded by

Ria Dcosta-036
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/ 4

Experiment-7

Name Roll No Branch


Leander Braganza 05 COMPS Batch A

Experiment - 7

Bankers Algorithm

Learning Write a program to demonstrate the concept of deadlock


Objectiv avoidance through Banker’s Algorithm
e:
Learning Students will be able to understand process deadlocks
Outcom
e:
Course CSL403.4
Outcome:
Program (PO 3) Design/ development of solutions: Breadth and
Outcom uniqueness of engineering problems i.e. the extent to which
e: problems are original and to which solutions have previously
been identified or codified

(PO 12) Life Long Learning


Bloom's Apply,Create
Taxonomy
Level:
Theory: Bankers Algorithm:-

 Bankers algorithm is applicable to the resource allocation system


with multiple instances of each resource type.
 It is less efficient than resource-allocation graph algorithm.
 Newly entered process should declare maximum number of
instances of each resource type which it may require.
 The request should not be more than total number of resources
in the system.
 System checks if allocation of requested resources will leave the
system in safe state. If it will the requested resources are
allocated.
 If system determines that resources cannot be allocated as it will
go in unsafe state, the requesting process should wait until other
process free the resources.

Algorithm : if
need < available
then
execute the process
New available=Available+Allocation
Else
do not execute go forward

//Need Matrix=Max-Allocation
Data Set : A[m]:Array A of size m shows the number of available
resources.

M[n][m]:Two dimensional array M shows maximum


requirement of the resources by each process. M [i][j] = k
indicates process Pi can request at the most k instances of
resource type Rj.

C[n][m]: Two dimensional array C shows current allocation


status of resources to each process. C[i][j] = k indicates
process Pi allocated k instances of resource type R j.

N[n][m]: Two dimensional array N shows the remaining


possible need of each process i.e N[i][j] = M[i][j] – C[i][j] . N[i]
[j] = k indicates process Pi may need additional k instances of
resource type Rj to accomplish the execution
Program Code: #include <stdio.h>
int main()
{
// P0, P1, P2, P3, P4 are the Process names here

int n, m, i, j, k;
n = 5; // Number of processes
m = 3; // Number of resources
int alloc[5][3] = { { 0, 1, 0 }, // P0 // Allocation Matrix
{ 2, 0, 0 }, // P1
{ 3, 0, 3 }, // P2
{ 2, 1, 1 }, // P3
{ 0, 0, 2 } }; // P4

int max[5][3] = { { 0, 0, 0 }, // P0 // MAX Matrix


{ 2, 0, 2 }, // P1
{ 0, 0, 0 }, // P2
{ 1, 0, 0 }, // P3
{ 0, 0, 2 } }; // P4

int avail[3] = { 0, 0, 0 }; // Available Resources

int f[n], ans[n], ind = 0;


for (k = 0; k < n; k++) {
f[k] = 0;
}
int need[n][m];
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++)
need[i][j] = max[i][j] - alloc[i][j];
}
int y = 0;
for (k = 0; k < 5; k++) {
for (i = 0; i < n; i++) {
if (f[i] == 0) {

int flag = 0;
for (j = 0; j < m; j++) {
if (need[i][j] > avail[j]){
flag = 1;
break;
}
}

if (flag == 0) {
ans[ind++] = i;
for (y = 0; y < m; y++)
avail[y] += alloc[i][y];
f[i] = 1;
}
}
}
}

int flag = 1;

for(int i=0;i<n;i++)
{
if(f[i]==0)
{
flag=0;
printf("The following system is not safe");
break;
}
}

if(flag==1)
{
printf("Following is the SAFE Sequence\n");
for (i = 0; i < n - 1; i++)
printf(" P%d ->", ans[i]);
printf(" P%d", ans[n - 1]);
}

return (0);

Outcome :

Conclusion : The Algorithm is successfully executed

References: 1. https://www.geeksforgeeks.org/bankers-algorithm-in-
operating-system-2/
2. https://www.studytonight.com/operating-system/
bankers-algorithm

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy