answersLogoWhite

0

What is banker's algorithm?

Updated: 10/3/2023
User Avatar

Wiki User

11y ago

Best Answer

#include <stdio.h>

int curr[5][5],maxclaim[5][5],avl[5];

int alloc[5]={0,0,0,0,0};

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

int count=0,i,j,exec,r,p;

int main(){

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

scanf("%d",&r);

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

scanf("%d",&p);

for(i=0;i<p;i++){

running[i]=1;

count++;

}

printf("\nEnter Claim Vector: ");

for(i=0;i<r;i++) scanf("%d",&maxres[i]);

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

for(i=0;i<p;i++){

for(j=0;j<r;j++) scanf("%d",&curr[i][j]);

}

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

for(i=0;i<p;i++){

for(j=0;j<r;j++) scanf("%d",&maxclaim[i][j]);

}

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

for(i=0;i<r;i++) printf("\t%d",maxres[i]);

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

for(i=0;i<p;i++){

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

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

printf("\n");

}

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

for(i=0;i<p;i++){

for(j=0;j<r;j++) printf("\t%d",maxclaim[i][j]);

printf("\n");

}

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

for(j=0;j<r;j++) alloc[j]+=curr[i][j];

printf("\nAllocated resources:");

for(i=0;i<r;i++) printf("\t%d",alloc[i]);

for(i=0;i<r;i++) avl[i]=maxres[i]-alloc[i];

printf("\nAvailable resources:");

for(i=0;i<r;i++) printf("\t%d",avl[i]);

printf("\n");

//Main procedure goes below to check for unsafe state.

while(count!=0){

safe=0;

for(i=0;i<p;i++){

if(running[i]){

exec=1;

for(j=0;j<r;j++){

if(maxclaim[i][j]-curr[i][j]>avl[j]){

exec=0;

break;

}

}

if(exec){

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

running[i]=0;

count--;

safe=1;

for(j=0;j<r;j++) avl[j]+=curr[i][j];

break;

}

}

}

if(!safe){

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

break;

}else

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

printf("\nAvailable vector:");

for(i=0;i<r;i++) printf("\t%d",avl[i]);

printf("\n");

}

}

User Avatar

Wiki User

11y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

11y ago

according to wikipendia "The Banker's algorithm is a resource allocation and deadlock avoidance algorithm developed by Edsger Dijkstra that tests for safety by simulating the allocation of predetermined maximum possible amounts of all resources, and then makes a "s-state" check to test for possible deadlock conditions for all other pending activities, before deciding whether allocation should be allowed to continue."

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is banker's algorithm?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Why Bankers algorithm to avoid deadlock is called so?

It is called that so that the algorithm will prevent such a financial situation.


How does bankers algorithm avoid deadlock It seems a very obvious algorithm where simply the resources whose needs are less than available are given the resources?

step 1: if(need &lt; available) True then, process allocated.. We find new available : old available + allocation step 2: else false go to step 1


Who hires bankers?

Bankers Retardo


Who is the target market for fixed deposit?

platimum bankers platimum bankers platimum bankers


Are bankers a salesperson?

no bankers are not sales people but they are the advisors


What is a group of bankers called?

A Wunch is what a group of bankers are called.


When was Bankers Hall created?

Bankers Hall was created in 1989.


What is the bankers duty?

Dominated by the banking industry, entrepreneurs, bankers said. Do bankers known as: capitalists, investors Bankers means good at breeding in the business vision into business reality of people


How are the expanded algorithm and the standard algorithm different?

They are different because standard algorithm is more common then the expanded algorithm


When was The Bankers created?

The Bankers was created in 1975.


What does bankers have to do with math?

Bankers count money and calculate how much to give you.


What is algorithm to write algorithm to the program to access a pointer variable in structure?

Here is the algorithm of the algorithm to write an algorithm to access a pointer in a variable. Algorithmically.name_of_the_structure dot name_of_the _field,eg:mystruct.pointerfield