Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Banker's Algorithm (in c): For this assignment, start with the attached bastarter.c. Your program should accept customer requests and releases in the format shown in

Banker's Algorithm (in c):

For this assignment, start with the attached bastarter.c. Your program should accept customer requests and releases in the format shown in the attached input.txt. The first number in each line is the customer number followed by a + (request) or a - (release). This is followed by the resources being requested or released. Your output should be the request or release that was input. If the input is a request, then your output should also append one of the following to the request line:

ACCEPTED - This indicates that the request was accepted

UNAVAILABLE - This indicates that there are currently not enough available resources to satisfy the request

UNSAFE - This indicates that satisfying the request would put the system in an unsafe state

The attached output.txt is the result of running the program as follows: ./a.out 10 5 7 < input.txt. If done correctly, your output should match the contents of the attached output.txt EXACTLY. (Use diff to compare.) Although you can use input.txt and output.txt for testing, be aware that your solution will be tested with a different set of input.

bastarter.c

#include  #include  #include  #include  #include  #define NUMBER_OF_CUSTOMERS 5 #define NUMBER_OF_RESOURCES 3 #define BUFSIZE 80 int available[NUMBER_OF_RESOURCES]; int maximum[NUMBER_OF_CUSTOMERS][NUMBER_OF_RESOURCES]; int allocation[NUMBER_OF_CUSTOMERS][NUMBER_OF_RESOURCES]; int need[NUMBER_OF_CUSTOMERS][NUMBER_OF_RESOURCES]; bool is_safe(); /* Set initial values for all arrays using the following: Customer Allocation Need Maximum 0 0 0 0 7 1 3 7 1 3 1 0 0 0 4 3 5 4 3 5 2 0 0 0 6 2 1 6 2 1 3 0 0 0 5 3 3 5 3 3 4 0 0 0 1 3 4 1 3 4 */ /* The above initial values only work when NUMBER_OF_CUSTOMERS is 3 */ void *initialize_resource_arrays(char* argv[]) { /* Loop control variables */ int c,r; /* Initialize available resources to command-line parameters */ for (r=0; r 

input:

2 + 1 2 1 1 + 3 1 4 0 + 3 1 2 3 + 3 2 3 4 + 1 1 1 2 - 1 1 1 3 + 3 2 3 1 - 3 1 2 0 + 3 1 2 4 - 1 1 1 3 + 3 2 3 0 - 2 1 1 1 + 3 2 3 3 - 1 1 2 1 + 3 2 3 4 + 1 3 1 2 + 4 1 1 0 + 2 1 1 1 - 3 2 3 4 + 1 3 1

output:

2 + 1 2 1 ACCEPTED 1 + 3 1 4 ACCEPTED 0 + 3 1 2 UNSAFE 3 + 3 2 3 UNAVAILABLE 4 + 1 1 1 ACCEPTED 2 - 1 1 1 3 + 3 2 3 UNAVAILABLE 1 - 3 1 2 0 + 3 1 2 ACCEPTED 4 - 1 1 1 3 + 3 2 3 ACCEPTED 0 - 2 1 1 1 + 3 2 3 UNAVAILABLE 3 - 1 1 2 1 + 3 2 3 ACCEPTED 4 + 1 3 1 UNAVAILABLE 2 + 4 1 1 UNAVAILABLE 0 + 2 1 1 UNAVAILABLE 1 - 3 2 3 4 + 1 3 1 UNSAFE

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

Step: 3

blur-text-image

Ace Your Homework with AI

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

Get Started

Students also viewed these Databases questions

Question

2 9 8 .

Answered: 1 week ago