Question
Banker's Algorithm in c: Banker's algorithm is a resource allocation and deadlock avoidance algorithm developed by Edsger Dijkstra that tests for safety by simulating the
Banker's Algorithm in c:
Banker's algorithm is a resource allocation and deadlock avoidance algorithm developed by Edsger Dijkstra that tests for safety by simulating the allocation of predetermined maximum possible amounts of all resources, and then makes an "s-state" check to test for possible deadlock conditions for all other pending activities, before deciding whether allocation should be allowed to continue.
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 (10, 5, 7 are the instances of the resources). 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.
The overall goal of this is to fill in the is_safe, request_resources, and release_resources to determine whether the various input (see below) are in a safe state (whether the resources The 10,5,7 < input.txt are the instances of the resources you are checking compared to the resources in the array already set up. The other methods just help set up the array, and the input from the command line. Please let me know if this answers your question.
#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 intput.txt:
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 1what output should look like:
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started