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 8.6.3. 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 8.6.3. The banker will keep track of the resources using the following data structures:
#define NUMBER OF CUSTOMERS 5 #define NUMBER OF RESOURCES 4
/* the available amount of each resource */ int available[NUMBER OF RESOURCES];
/*the maximum demand of each customer */
int maximum[NUMBER OF CUSTOMERS][NUMBER OF RESOURCES];
/* the amount currently allocated to each customer */ int allocation[NUMBER OF CUSTOMERS][NUMBER OF RESOURCES];
/* the remaining need of each customer */
int need[NUMBER OF CUSTOMERS][NUMBER OF RESOURCES];
Programming Projects P-46
The banker will grant a request if it satisfies the safety algorithm outlined in Section 8.6.3.1. 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 resources(int customer num, int request[]);
void release resources(int customer num, int release[]);
The request resources() function should return 0 if successful and 1 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:
./a.out 10578
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:
6,4,7,3
4,2,3,2
2,5,3,3
6,3,3,2
5,6,7,5
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 0 were to request the resources (3,1,2,1), the following command would be entered:
RQ 03121
Your program would then output whether the request would be satisfied or denied using the safety algorithm outlined in Section 8.6.3.1.
Similarly, if customer 4 were to release the resources (1,2,3,1), the user would
enter the following command:
RL 41231
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 blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!