Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

Please write a program that can examine the Bankers algorithm to check a request. When the system allocates the resource according to the request and

Please write a program that can examine the Bankers algorithm to check a request. When the system allocates the resource according to the request and the system is in a safe state, the request will be accepted. The sample program can check only one request. Please write a program( in C ) to check a serial of requests with different command types:

Sample codes

#include

#define MAXP 10

#define MAXR 10

int maximal[MAXP][MAXR],allocation[MAXP][MAXR],available[MAXR];

int command[MAXR+2];

//command[0]:cmd type; [1]:process id; [2]-[n]:resource type

//command type 0: finish 1:request 2:release

int p,r; //p: amout of process; r: amount of resource

void set_init()

{

FILE *init;

int i,j;

if((init=fopen("init.txt","r"))<0)

{

perror("init file open error");

return;

}

fscanf(init,"%d",&p);

fscanf(init,"%d",&r);

printf("%d %d ",p,r);

for (i=0;i

{

for (j=0;j

{

fscanf(init,"%d",&allocation[i][j]);

}

}

for (i=0;i

{

for (j=0;j

{

fscanf(init,"%d",&maximal[i][j]);

}

}

for (j=0;j

{

fscanf(init,"%d",&available[j]);

}

fclose(init);

}

void get_command()

{

FILE *cmd;

int i;

if((cmd=fopen("cmd.txt","r"))<0)

{

perror("command file open error");

return;

}

printf("command");

for (i=0;i

{

fscanf(cmd,"%d",&command[i]);

printf("[%d]",command[i]);

}

printf(" ");

}

init.txt

5 3

0 1 0

2 0 0

3 0 2

2 1 1

0 0 2

7 5 3

3 2 2

9 0 2

2 2 2

4 3 3

3 3 2

cmd.txt

1 4 3 3 0

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image
Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Strategic Database Technology Management For The Year 2000

Authors: Alan Simon

1st Edition

155860264X, 978-1558602649

More Books

Students explore these related Databases questions