Question: Help Description: Program in c with arrays and math The objective of this project is to develop a program in C that implements the banker
Help Description: Program in c with arrays and math
The objective of this project is to develop a program in C that implements the bankers algorithm. The program simulates resource allocation and management in a multiprocess environment where customers make requests and release resources from a central bank. The banker, acting as the resource manager, will grant requests only if they maintain system safety, ensuring deadlock avoidance.
The Banker:
The banker evaluates requests from n customers for m types of resources. To manage resources effectively, the banker maintains the following data structures:
#define NUMBEROFCUSTOMERS
#define NUMBEROFRESOURCES
The available amount of each resource
int availableNUMBEROFRESOURCES;
The maximum demand of each customer
int maximumNUMBEROFCUSTOMERSNUMBEROFRESOURCES;
The amount currently allocated to each customer
int allocationNUMBEROFCUSTOMERSNUMBEROFRESOURCES;
The remaining need of each customer
int needNUMBEROFCUSTOMERSNUMBEROFRESOURCES;
The banker grants a request if it adheres to the safety algorithm. Requests that jeopardize system safety are denied. Function prototypes for requesting and releasing resources are defined as follows:
int requestresourcesint customernum, int request;
void releaseresourcesint customernum, int release;
The requestresources function returns upon successful allocation and upon failure.
Testing Your Implementation:
Design a program that enables user interaction for requesting and releasing resources, as well as displaying the current values of the different data structures available maximum, allocation, and need associated with the bankers algorithm.
Invoke your program by passing the number of resources of each type through the command line. For instance, if there are 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, execute your program as follows:
aout
The available array will be initialized with these values. Initially, the program reads a file containing the maximum number of requests for each customer. For example, if there are five customers and four resources, the input file format is as follows:
Each line in the input file represents the maximum request of each resource type for each customer. The program initializes the maximum array accordingly.
The user then enters commands to request resources, release resources, or display the current values of the data structures. Use RQ for requesting resources, RL for releasing resources, and to output the values of the different data structures. For instance, to request resources for customer enter the following command:
RQ
The program outputs whether the request would be satisfied or denied based on the safety algorithm. Similarly, to release resources for customer enter the command:
RL
Finally, entering the command outputs the values of the available, maximum, allocation, and need arrays.
Sample execution output THIS IS JUST AN EXAMPLE:
Welcome to the Banker's Algorithm Simulation
Initializing system with resources:
Available:
Reading maximum request file...
Maximum requests initialized:
Customer :
Customer :
Customer :
Customer :
Customer :
Please enter commands:
RQ customernum resource resource resource resource to request resources
RL customernum resource resource resource resource to release resources
to display the current values of the data structures
'exit' to quit
Command: RQ
Requesting resources for Customer
Request granted. System is in a safe state.
Command: RQ
Requesting resources for Customer
Request granted. System is in a safe state.
Command: RQ
Requesting resources for Customer
Request denied. System would be left in an unsafe state.
Command: RL
Releasing resources for Customer
Resources released successfully.
Command:
Current system state:
Available:
Maximum:
Customer :
Customer :
Customer :
Customer :
Customer :
Allocation:
Customer :
Customer :
Customer :
Customer :
Customer :
Need:
Customer :
Customer :
Customer :
Customer :
Customer :
Command: exit
Exiting program. Goodbye!
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
