Question: Banker s Algorithm For this project, you will write a program, in C , that implements the banker s algo - rithm discussed in Section
Bankers Algorithm
For this project, you will write a program, in C that implements the bankers algo rithm discussed in Section Customers request and release resources from the bank. The banker will grant a request only if it leaves the system in a safe state. A request that leaves the system in an unsafe state will be denied.
The Banker
The banker will consider requests from n customers for m resources types, as outlined in Section The banker will keep track of the resources using the following data structures:
#define NUMBER OF CUSTOMERS #define NUMBER OF RESOURCES
the available amount of each resource int availableNUMBER OF RESOURCES;
the maximum demand of each customer
int maximumNUMBER OF CUSTOMERSNUMBER OF RESOURCES;
the amount currently allocated to each customer int allocationNUMBER OF CUSTOMERSNUMBER OF RESOURCES;
the remaining need of each customer
int needNUMBER OF CUSTOMERSNUMBER OF RESOURCES;
Programming Projects P
The banker will grant a request if it satisfies the safety algorithm outlined in Section If a request does not leave the system in a safe state, the banker will deny it Function prototypes for requesting and releasing resources are as follows:
int request resourcesint customer num, int request;
void release resourcesint customer num, int release;
The request resources function should return if successful and if
unsuccessful.
Testing Your Implementation
Design a program that allows the user to interactively enter a request for resources, to release resources, or to output the values of the different data structures available maximum, allocation, and need used with the bankers algorithm.
You should invoke your program by passing the number of resources of each type on the command line. For example, if there were four resource types, with ten instances of the first type, five of the second type, seven of the third type, and eight of the fourth type, you would invoke your program as follows:
aout
The available array would be initialized to these values.
Your program will initially read in a file containing the maximum number
of requests for each customer. For example, if there are five customers and four resources, the input file would appear as follows:
where each line in the input file represents the maximum request of each resource type for each customer. Your program will initialize the maximum array to these values.
Your program will then have the user enter commands responding to a request of resources, a release of resources, or the current values of the different data structures. Use the command RQ for requesting resources, RL for releas ing resources, and to output the values of the different data structures. For example, if customer were to request the resources the following command would be entered:
RQ
Your program would then output whether the request would be satisfied or denied using the safety algorithm outlined in Section
Similarly, if customer were to release the resources the user would
enter the following command:
RL
Finally, if the command is entered, your program would output the values of the available, maximum, allocation, and need arrays.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
