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

Banker Algorithm Code

The document contains code for the Banker Algorithm, which is used for deadlock avoidance in operating systems. It initializes processes and resources, calculates the need matrix, and determines a safe sequence for process execution. However, the code has several syntax errors and logical issues that need to be corrected for proper functionality.

Uploaded by

ahmedkhwaja193
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Banker Algorithm Code

The document contains code for the Banker Algorithm, which is used for deadlock avoidance in operating systems. It initializes processes and resources, calculates the need matrix, and determines a safe sequence for process execution. However, the code has several syntax errors and logical issues that need to be corrected for proper functionality.

Uploaded by

ahmedkhwaja193
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

BANKER ALGORITHM CODE

#include<stdio.h>
int main(){
//p0,p1,p2,p3,p4
int n,m,i,j,k;
n=5//number of process
m=3//number of resouc
int alloc[5][3]={{0,1,0}},
{2,0,0}//p1
{3,0,3}//p2
{2,1,1}//p3//bank
{0,0,2}//p4//atm
int max [5][3]={{7,5,3}},//p0//max
{3,2,2}//P11
{9,0,2}//P12
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<mj++){
if(need[i][j]>avail[j]){
flag=1;
breal;}}
if(flag==0)
ans[ind++]=i;
for(y=0;y<m;y++){
avail[y]+=alloc[i][y]

{2,2,2}//P3//atm
{4,3,3}//P4//bank
int avail[3]={3,3,2}//Available
int f[n], ans[n],ind=0;
for(k==0,k<n;k++){
f[k]=0
}
int need [n][m]
f[i]=1;
}}}}
int flag=1;
{
printf("Following is the safe sequence");
for(i=0;i,n-1;i++){
printf("P%d",ans[n-1]);
}
return(0);}

You might also like