You are on page 1of 2

import java.net.

*;
import java.io.*;
public class deadlock
{
public static void main(String[] args)throws IOException
{
int i,j,n,m;
int alloc[][]=new int[50][50];
int request[][]=new int[50][50];
int available[]=new int[50];
int finish[]=new int[50];
int work=new int[50];
int temp=new temp[50];
int count=0;
clrscr();
printf("Enter number of process\n");
scanf("%d",&n);
printf("Enter number of resources\n");
scanf("%d",&m);
printf("Process = %d Resources = %d",n,m);
printf("\nEnter allocation matrix\n");
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
scanf("%d",&alloc[i][j]);
}
}
printf("\n************Allocation matrix***********\n\n");
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
printf("%2d ",alloc[i][j]);
}
printf("\n");
}
printf("\nEnter request matrix\n");
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
scanf("%d",&request[i][j]);
}
}
printf("\n************Request matrix**************\n\n");
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
printf("%2d ",request[i][j]);
}
printf("\n");
}
printf("Enter available resource vector\n");
for(i=0;i<m;i++)
{
scanf("%d",&available[i]);
}
printf("\nAvailable resource vector\n");

for(i=0;i<m;i++)
{
printf("%2d ",available[i]);
}
printf("\n");
for(i=0;i<m;i++)
{
work[i]=available[i];
}
for(i=0;i<n;i++)
{
finish[i]=false;
}
check:
for(i=0;i<n;)
{
if(finish[i]==false)
{
for(j=0;j<m;j++)
{
if(request[i][j]<=work[j])
{
// temp[j]=work[j]+alloc[i][j];
count++;
if(count==m)
{
int c=0;
for(c=0;c<m;c++)
{
work[c]+=alloc[i][c];
printf(" %d ",work[c]);
}
// pr
intf("\n");
finish[i]=true;
// count1++;
// if(count1==n)
// {
// goto bottom;
// }
}
}
}
}
else i++;
}
bottom:
getch();
}
}

You might also like