Académique Documents
Professionnel Documents
Culture Documents
Roll No. 45
#include<iostream>
using namespace std;
int main()
{
int n,r;
cout<<"Total no. of processes n: ";
cin>>n;
cout<<"Resource Types r: ";
cin>>r;
int procSequence[n];
int available[r];
int allocation[n][r];
int max[n][r];
int need[n][r];
bool finish[n] = {false};
int finishCnt = 0;
cout<<" ";
for(int j=0; j<r; j++)
{
cout<<max[i][j]<<" ";
}
cout<<" ";
for(int j=0; j<r; j++)
{
cout<<need[i][j]<<" ";
}
cout<<endl;
}
if(j==r)
{
cout<<"Sufficient Resource\n";
cout<<"Process P"<<i<<" finished.\n";
procSequence[finishCnt] = i;
finish[i] = true;
finishCnt++;
cout<<"finishCnt : "<<finishCnt<<endl;
cout<<"New Available = ";
for(int k=0; k<r; k++)
{
available[k] = available[k] + allocation[i][k];
cout<<available[k]<<" ";
}
found_flag = true;
cout<<endl<<endl;
}
}
}
if(found_flag == false)
{
cout<<"System is not in safe state\n";
return 1;
}
}