Please fix the errors in this code to make it have an output similar to this:   Here is the C code to be fixed: #include int Read(int, int, int [][10], int [][10],int []

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

Please fix the errors in this code to make it have an output similar to this:

 

Here is the C code to be fixed:

#include<stdio.h>

int Read(int, int, int [][10], int [][10],int [],int []);
int *Process(int, int, int [][10], int [][10],int [],int [], int []);
void Display (int, int[], int, int[], int [], int [][10]);

static int mark[20];
int i,j,np,nr;
int alloc[10][10],request[10][10],avail[10],r[10],w[10];

int main()
{


Read (np, nr, alloc[10], request[10], avail[], r[]);
Process (np, nr, alloc[10], request[10],avail[],w[], mark[]);
Display (np, request[10],nr, mark[], r[], alloc[10]);

return 0;
}

int Read(int np, int nr, int alloc[][10], int request[][10],int avail[],int r[])
{
   int i,j;
   FILE* file = fopen ("input.txt", "r");
  
// get the no of process
   fscanf (file, "%d", &np);
// get the no of resources
   fscanf (file, "%d", &nr);
// get availale resources

   for(i=0;i<nr;i++)
   {
       fscanf (file, "%d", &r[i]);
   }

// get the allocation matrix
   for(i=0;i<np;i++)
   for(j=0;j<nr;j++)
   fscanf (file, "%d", &alloc[i][j]);

// get the request matrix

   for(i=0;i<np;i++)
   for(j=0;j<nr;j++)
   fscanf (file, "%d", &request[i][j]);
  
   fclose (file);
   return request,alloc,np,nr;
}

int *Process(int np, int nr, int alloc[][10], int request[][10],int avail[],int w[], int mark[])
{
   int i,j,count=0;
   for(i=0;i<np;i++)
   {
       for(j=0;j<nr;j++)
       {
           if(alloc[i][j]==0)
               count++;

           else
           break;
       }

       if(count==nr)
           mark[i]=1;
   }  

   for(j=0;j<nr;j++)
   w[j]=avail[j];

//mark processes with request less than or equal to W
   for(i=0;i<np;i++)
   {
       int canbeprocessed=0;
       if(mark[i]!=1)
       {
           for(j=0;j<nr;j++)
           {
               if(request[i][j]<=w[j])
               canbeprocessed=1;
               else
               {
                   canbeprocessed=0;
                   break;
               }

           }

       if(canbeprocessed)
       {  
           mark[i]=1;
           for(j=0;j<nr;j++)
           w[j]+=alloc[i][j];
       }
       }
   }
  
   return w;
}

void Display(int np, int request[][10], int nr, int mark, int r[], int alloc[][10])
{
   int i,j,deadlock=0;
  
   printf("Numer of processes: %d",np);
   printf("\n");
   printf("Numer of resources: %d",nr);
   printf("\n");
       printf("\nAvailbaility vector\n");

   for(i=0;i<nr;i++)
   {
       printf("%d ",r[i]);
   }

   printf("\n");
   printf("\nAllocation Matrix\n");
  
   for(i=0;i<np;i++)
   {  
       for(j=0;j<nr;j++)
       printf("%d ", alloc[i][j]);
       printf("\n");
   }

   printf("\n");

   printf("Request Matrix\n");
   for(i=0;i<np;i++)
       {
           for(j=0;j<nr;j++)
           printf("%d ", request[i][j]);
           printf("\n");
       }  
   printf("\n");
  
  
   for(i=0;i<np;i++)
   {
   if(mark[i]!=1)
       deadlock=1;
   if(deadlock)
       printf("\nThere is a Deadlock");
   else
       printf("\nThere is a no Deadlock");
   }
   return;
}

For Basis:

#include<stdio.h>

static int mark[20];
int i,j,np,nr;

int main(){
int alloc[10][10],request[10][10],avail[10],r[10],w[10];

// open the input file
// use fscanf (file, "%d", &x) to read integer from file
FILE* file = fopen ("input.txt", "r");

// get the no of process
fscanf (file, "%d", &np);
// get the no of resources
fscanf (file, "%d", &nr);
// get availale resources
for(i=0;i<nr;i++){
fscanf (file, "%d", &r[i]);
}

// get the allocation matrix
for(i=0;i<np;i++)
for(j=0;j<nr;j++)
fscanf (file, "%d", &alloc[i][j]);

// get the request matrix

for(i=0;i<np;i++)
for(j=0;j<nr;j++)
fscanf (file, "%d", &request[i][j]);


// print all the details read from input to console
printf("Numer of processes: %d",np);
printf("\n");
printf("Numer of resources: %d",nr);
printf("\n");
printf("\nAvailbaility vector\n");

for(i=0;i<nr;i++){
printf("%d ",r[i]);
}

printf("\n");
printf("\nAllocation Matrix\n");
for(i=0;i<np;i++){
  
for(j=0;j<nr;j++)
printf("%d ", alloc[i][j]);
printf("\n");
}

printf("\n");

printf("Request Matrix\n");
for(i=0;i<np;i++){
  
for(j=0;j<nr;j++)
printf("%d ", request[i][j]);
printf("\n");
}

printf("\n");
//marking processes with zero allocation
for(i=0;i<np;i++){
  
int count=0;
for(j=0;j<nr;j++){
  
if(alloc[i][j]==0)
count++;

else

break;
}

if(count==nr)
mark[i]=1;
}
// initialize W with avail
for(j=0;j<nr;j++)
w[j]=avail[j];

//mark processes with request less than or equal to W
for(i=0;i<np;i++){
  
int canbeprocessed=0;
if(mark[i]!=1){
  
for(j=0;j<nr;j++){
  
if(request[i][j]<=w[j])
canbeprocessed=1;

else{
canbeprocessed=0;
break;
}

}

if(canbeprocessed){
mark[i]=1;

for(j=0;j<nr;j++)
w[j]+=alloc[i][j];
       }
   }
}

//checking for unmarked processes
int deadlock=0;
for(i=0;i<np;i++)
if(mark[i]!=1)
deadlock=1;

if(deadlock)
printf("\nThere is a Deadlock");
else
printf("\nThere is a no Deadlock");
fclose (file);
}

Numer of processes: 4
Numer of resources: 5
Availbaility vector
2 1 1 2 1
Allocation Matrix
1 e 1 1 e
1 1 0 0 0
e e e 1 e
e e e e e
Request Matrix
e 1 e e 1
e e 1 e 1
e e e 0 1
1е1 ө1
Transcribed Image Text:Numer of processes: 4 Numer of resources: 5 Availbaility vector 2 1 1 2 1 Allocation Matrix 1 e 1 1 e 1 1 0 0 0 e e e 1 e e e e e e Request Matrix e 1 e e 1 e e 1 e 1 e e e 0 1 1е1 ө1
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Datatypes
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education