This program emulates a resource manager capable of running with two scheduling algorithms, First Come First Served, and Banker's Algorithm. The program takes in task activity information and will output the information corresponding to how the time taken for task to complete.
To compile the code and create an executable, run:
gcc -o banker banker.c.c activityQueue.c.c list.c
This will create a banker executable that you can now use to run the resource manager. To run on the command line, provide input in the following format:
./banker (input.txt)
Where the input.txt contains the the number of tasks, the number of resource, and their corresponding unit amounts
The activity struct describes the shape of an activity/instruction. Each activity contains:
- char name; The activity's name
- int task_number; The activity's task number
- int resource_type; The activity's resource type
- int unit_amount; The amount needed from resource type
The activityQueue.h file represents a queue data structure which the resource manager utilizes to the input sequences. It contains:
Represents a single node of the queue
- Activity *data; Node's data
- struct QueueNode *next; The next node
Queue struct
- QueueNode *front; The beginning node of the queue
- QueueNode *rear; The last node of the queue
- int size; The length of the queue
Functions
- Queue *createQueue(); Initializes a queue
- int isEmptyActivityQueue(Queue *activityQueue); Check if queue is empty
- int getSizeActivityQueue(Queue *activityQueue); Get the size of the queue
- void enqueueActivity(Queue *activityQueue, Activity *activity); Adds element to end of queue
- Activity *dequeueActivity(Queue *activityQueue); Takes element from the front of queue
- void destroyActivityQueue(Queue *activityQueue); Clear the queue
The list.h file represents a list data structure that holds the blocked activities. It contains:
Represents a single node of the list
- Activity *data; Node's data
- struct ListNode *next The next node
List struct
- ListNode *head The had of the list
- int size The size of the list
Functions
- List *createList(); Initializes a list
- int isEmpty(List *list); Check if the list is empty
- int getSize(List *list); Get the size of the list
- void appendToList(List *list, Activity *activity); Add to the end of the list
- void removeFromList(List *list, Activity *activity); Remove from front of the list
- void removeAtIndex(List *list, int index); Remove at a certain index of the list
- void removeByTaskNumber(List *list, int task_number); Remove from the list by a task number
- void clearList(List *list); Clear all the elements of the list
- void destroyList(List *list); Clear all elements and free the space in memory
The banker file takes a command line input given by a .txt file with the corresponding task activities.
The first line of the .txt file gives the number of tasks, the number of resources, and the amount of units per each of the resources given sequentially.
The next set of activities represents the instructions corresponding to the first task. Each activity contains a name, the task it is instructing, the resource it uses, and the units it uses.
Each set of instructions then respond to the remaining tasks.