Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Below is code for a banker's algorithm project in c. The Banker's algorithm is a resource allocation and deadlock avoidance algorithm developed by Edsger Dijkstra

Below is code for a banker's algorithm project in c.

The 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 a "s-state" check to test for possible deadlock conditions for all other pending activities, before deciding whether allocation should be allowed to continue.

In this program, the is_safe, request_resources, and release_resources need to be filled it. When compling this program use ./a.out 10 5 7 < input.txt (input file is provided below and what the ouput should look like). 10 5 7 are 3 parsed arguments that are stored in the array and check to see if these resources will result in a safe state. The goal is to check whether the resources are accepted (aka safe), unavaliable, or unsafe. a "+" means resources are being requested, and a "-" means they are being released.

Here is the code that needs to be edited:

#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.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 1

Below is what the 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

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