System with m process and n resource types. Accept number of instances for every resource type. For each process accept the allocation and maximum requirement matrices. Write a program to check if given request of process can be granted immediately or not.

System with m process and n resource types. Accept number of instances for every resource type. For each process accept the allocation and maximum requirement matrices. Write a program to check if given request of process can be granted immediately or not.


Program:
#include <stdio.h>
#include <stdlib.h>

void main(){
 setbuf(stdout,NULL);
 int m,n,i,j,al[10][10],av[10],rq[10],tr[10],temp;
 printf("\nEnter the number of processes:");
 scanf("%d",&m);
 printf("\nEnter the number of resources:");
 scanf("%d",&n);
 printf("\nEnter the allocation matrix:");
 for(i=0;i<m;i++){
  for(j=0;j<n;j++){
   scanf("%d",&al[i][j]);
  }
 }
 printf("\nEnter Total resources array:");
 for(i=0;i<n;i++){
  scanf("%d",&tr[i]);
 }
 printf("\nEnter the request array:");
 for(i=0;i<n;i++){
  scanf("%d",&rq[i]);
 }

 for(i=0;i<n;i++){
  temp=0;
  for(j=0;j<m;j++){
   temp+=al[j][i];
  }
  av[i]=tr[i]-temp;
 }
 for(i=0;i<n;i++){
  if(rq[i]>av[i]){
   printf("\nNot Granted");
   exit(0);
  }
 }
 printf("\nYes Granted.");
}

Post a Comment

Previous Post Next Post