用 Banker’s algorithm 解决操作系统中的死锁问题,并通过测试。
Purpose
In this assignment, you will write a complete C++ program that simulates the
Banker’s algorithm for Deadlock avoidance.
Time: Your softcopy must be in Prog4 directory under our class directory
(cs3270a) on BGUnix by 11:00AM on the due date. In addition, the copy of the
program and other required files must be tar and gzip, and submitted and
Canvas.
Assignment
This assignment will help you better-understand the Banker’s algorithm for
deadlock avoidance. Your task is to write a C/C++ program, on BGUnix, which
implement the algorithm for a given state of a system. This is be an
individual assignment.
Background
The resource-allocation-graph algorithm for deadlock avoidance is not
applicable to a resource-allocation system with multiple instances of each
resource type. Banker’s algorithm is applicable to such a system but is less
efficient than the resource-allocation graph scheme.
When a new process enters the system, it must declare the maximum number of
instances of each resource type that it many need. This number may not exceed
the total number of resources in the system. When a user/process requests a
set of resources, the system must determine whether the allocation of these
resources will leave the system in a safe state. If it will, the resources are
allocated; otherwise, the process must wait until some other processes release
enough resources.
Details
Your task is to implement the Banker’s algorithm for a given system to avoid
the deadlock.
- A snapshot of a system is given in an input file (named: system.txt)
- Input file format:
- First line : # of processes (n)
- Second line : # of resources (m)
- Next m lines : nxm Allocation matrix
- Next m lines : nxm Claim matrix
- Next line : m Available vector
- Determine whether the system is in a safe state.
- In addition, your program should also take keyboard inputs from the user.
- Allow the program to end when “q” is entered.
- Allow the user to enter a process request when “p” is entered.
- For example,
- (1) pressing a “p” key process request mode
- (2) entering process index “1” (e.g., for Process 1)
- (3) entering new request e.g., “0 4 2 0” is a new request for four resources
- For example,
- For each new request for a process, determine whether the request can be granted immediately or not.
- Your program should create an output file which contains all the steps of the Banker’s algorithm.
- Contents of the initial Allocation matrix, Claim matrix, Available vector, Need matrix, and Resource vector should be shown side by side
- Changes of the Available vector and Available, Need matrices should be also shown for each iteration of the algorithm
- Results of the algorithm (show how it is in a safe or unsafe state).
- Name your program as prog4.cpp
- Document your program properly. Program description, program structure/architecture, key functions/methods, key variables should be explained. How to run the program and any other feature about your program should also be described.
Softcopy submission
- Your softcopy must be in Prog4 directory under our class directory (cs3270a) on BGUnix by 11:00AM on the due date.
- You will need to submit all program source files, a readme file (which explains how to compile and run your program, including example commands), and a MS Word file which contains the screen capture of the outputs as ONE tared and gzipped file by 11:00AM on the due date. Use the following command to create one file for all files:
tar -czvf prog4-[your-last-names].tar.gz *.cpp (or *.c) *.h *.[all-other-files-extension]
tar -xzvf prog4-[your- last-names].tar.gz
command will be used to extract the files.
- Please note that submissions with wrong formats/files/names will be discarded.
Grade Distribution
- Not submitted with the required formats/files/names 0 point (no grading)
- Readme file and the program description include the compiling and running instruction: 3 points
- Other program documentation and comments: 3 points
- Reading of input data is done correctly: 4 points
- Initial system’s state is determined correctly: 7 points
- Additional user input done correctly: 5 points
- New system’s state is determined correctly: 7 points
- Steps of the algorithm is shown correctly: 5 points
- Program readability (structure, indentation, and spacing): 3 points
- Reasonable screen captured output: 3 points