Академический Документы
Профессиональный Документы
Культура Документы
• The Banker’s algorithm is best known of avoidance strategies. The resource allocation
graph algorithm suitable to resource allocation system with single instance of each
resource type. It is not suitable for multiple instance of each resource type.
• Banker’s algorithm is suitable for resource allocation system with multiple instance of
each resource type. Algorithm makes decision on granting resource best on wether or
not granting request will put system into an unsafe state.
• Several data structure maintained in Banker’s algorithm, say Available, Max,
Allocation, Need.
ALGORITHM :
1
• Whether the system deny or postponed an impossible or unsafe request is a decision
specific to operating system.
PROGRAM :
class Banker_algo
{
public static void main(String args[])throws IOException
{
Scanner sc = new Scanner(System.in);
int Allocation[][]=new int[5][3];
int Max[][]=new int[5][3];
int Need_req[][]=new int[5][3];
int Available[]=new int[3];
int p[]={0,1,2,3,4};
System.out.println("Enter the Allocation");
for(int i=0;i<5;i++)
for(int j=0;j<3;j++)
Allocation[i][j]=sc.nextInt();
System.out.println("Enter the maximum requirment");
for(int i=0;i<5;i++)
for(int j=0;j<3;j++)
Max[i][j]=sc.nextInt();
System.out.println("Enter the Availaible fpr processes zero for (p[0])");
for(int j=0;j<3;j++)
Available[j]=sc.nextInt();
//to find the required need for process max[][]-Allocation[][]
for(int i=0;i<5;i++)
for(int j=0;j<3;j++)
Need_req[i][j]=Max[i][j]-Allocation[i][j];
int x=0;
while (x<5)
{
for(int i=0;i<5;i++)
{
for(int j=0;j<1;j++)
if(Need_req[i][j]<=Available[j] && Need_req[i][j+1]<=Available[j+1] &&
Need_req[i]
[j+2]<=Available[j+2])
{
for(int s=0;s<3;s++)
{
Available[s]= Available[s]-Need_req[i][s]+Max[i][s];
Need_req[i][s]=100;
}
System.out.println("Available =");
for(int s=0;s<3;s++)
2
System.out.println(" "+Available[s]+" ");
System.out.println();
System.out.println("process p["+i+"] is over ");
x=x+1;
}
}
}//while
}///main
}//class
OUTPUT:
3
2
4
FLOWCHART: START
for i=0 to 5 do
for j=0 to 3 do
for i=0 to 5 do
for j=0 to 3 do
Need_req[i][j] Max[i][j]-Allocation[i][j]
Max[i][j]-Allocation[i][j]
A 5
A
Initialise x to 0.
Available[s]= Available[s]-Need_req[i][s]+Max[i][s]
Need_req[i][s]=100
xx+1
STOP
CONCLUSION:
Hence we have studied and implemented Bankers algorithm for deadlock detection.