C PROGRAM TO IMPLEMENT EDGE CHASING DEADLOCK DETECTION ALGORITHM

Saturday, 7 January 2017


#include<stdio.h>
#include<conio.h>
void main()
{
 int d[7][7];
 int i,j,n,a;
 int res;
 clrscr();
 printf("Enter the number of nodes\n\n");
 scanf("%d",&n);
 printf("Enter the elements of Dependency matrix");
 for(i=0;i<n;i++)
 {
   for(j=0;j<n;j++)
   {
  scanf("%d",&d[i][j]);
   }
  }
  d[0][1]=1;
  d[1][2]=1;
  d[2][3]=1;
printf("DEPENDECNY MATRIS IS:\n");
 for(i=0;i<n;i++)
 { for(j=0;j<n;j++)
  {
 printf("%d",d[i][j]);
  }
 }
  getch();
}

OUTPUT-



C PROGRAM TO IMPLEMENT HAUNG’S TERMINATION DETECTION


#include<stdio.h>
#include<conio.h>
void main()
{
 double p[3];
 double c=1;
 int k,j,res,res1,i,now,now1,con;
 clrscr();
 for(i=0;i<3;i++)
 {
  p[i]=0;
 }
 printf("\nWhich process do you want to start?\n");
 k=0;
 printf("p[%d] OR p[%d] OR p[%d]",k,k+1,k+2);
 printf("\nenter the process no.(0/1/2):\n");
 scanf("%d",&j);
 p[j]=0.5;
 c=c-p[j];
 printf("\nDoes process C(controller)invokes any other process:\nFor Yes-Press 1\nFor No-press 0\n");
 scanf("%d",&res);
 if(res==1)
 {
  printf("\nWhich process will it invoke(1 OR 2):\n");
  scanf("%d",&now);
  p[now]=0.25;
  c=c-0.25;
 }
 printf("\nDoes process C(controller)invokes any other process:\nFor Yes-Press 1\nFor No-press 0\n");
 scanf("%d",&res1);
 if(res1==1)
 {
  printf("\nWill it invoke(1 OR 2):\n");
  p[now1]=0.25;
  c=c-0.25;
 }
 for(i=0;i<3;i++)
 {
  printf("\nIs Process p[%d] is completed:?\nfor yes-press 1\nfor No-press 0\n",i);
  scanf("%d",&con);
  if(con==1)
  {
   c=c+p[i];
  }
 }
 if(c==1)
 {
  printf("\nAll Processes are COMPLETED");
 }
 else
 {
  printf("\nSome PROCESS is NOT Complete");
 }
 getch();    


  }

OUTPUT-



Related Posts Plugin for WordPress, Blogger...
Related Posts Plugin for WordPress, Blogger...
 

Most Reading

Labels