Program – Deadlock detection algorithm

by Nideesh C on April 17, 2011 · 0 comments

in C Programming




#include<stdio.h>
#include<conio.h>
void main()
{
int found,flag,l,p[4][5],tp,c[4][5],i,j,k=1,m[5],r[5],a[5],temp[5],sum=0;
clrscr();
printf("enter total no of processes");
scanf("%d",&tp);
printf("enter clain matrix");
for(i=1;i<=4;i++)
for(j=1;j<=5;j++)
{
scanf("%d",&c[i][j]);
}
printf("enter allocation matrix");
for(i=1;i<=4;i++)
for(j=1;j<=5;j++)
{
scanf("%d",&p[i][j]);
}
printf("enter resource vector:\n");
for(i=1;i<=5;i++)
{
scanf("%d",&r[i]);
}
printf("enter availability vector:\n");
for(i=1;i<=5;i++)
{
scanf("%d",&a[i]);
temp[i]=a[i];
}
for(i=1;i<=4;i++)
{
sum=0;
for(j=1;j<=5;j++)
{
sum+=p[i][j];
}
if(sum==0)
{
m[k]=i;
k++;
}
}
for(i=1;i<=4;i++)
{
for(l=1;l<k;l++)
if(i!=m[l])
{
flag=1;
for(j=1;j<=5;j++)
if(c[i][j]>temp[j])
{
flag=0;
break;
}
}
if(flag==1)
{
m[k]=i;
k++;
for(j=1;j<=5;j++)
temp[j]+=p[i][j];
}
}
printf("deadlock causing processes are:");
for(j=1;j<=tp;j++)
{
found=0;
for(i=1;i<k;i++)
{
if(j==m[i])
found=1;
}
if(found==0)
printf("%d\t",j);
}
getch();
}

INPUT:
 enter total no. of processes : 4
 enter claim matrix :
 0 1 0 0 1
 0 0 1 0 1
 0 0 0 0 1
 1 0 1 0 1
 enter allocation matrix :
 1 0 1 1 0
 1 1 0 0 0
 0 0 0 1 0
 0 0 0 0 0
 enter resource vector :
 2 1 1 2 1
 enter the availability vector :
 0 0 0 0 1

OUTPUT :
 deadlock causing processes are : 1 2



Not Satisfied ? Just search & get the result

Related Posts Plugin for WordPress, Blogger...
Be Sociable, Share!

Related posts:

  1. C Program to accept two matrices and check if they are equal
  2. C Program to check if a given matrix is an identity matrix
  3. C program to accept a matrix of order M x N and find the sum of each row and each column of a matrix
  4. C program to find accept a matrix of order M x N and find the sum of the main diagonal and off diagonal elements
  5. C program to accept a matrix of order MxN and find the trace and normal of a matrix HINT:Trace is defined as the sum of main diagonal elements and Normal is defined as square root of the sum of all the elements

Leave a Comment

Previous post:

Next post: