Question: How to write a banker's algorithm program that reads text file and gives output txt file? This assignment uses C or C++ This assignment involves

How to write a banker's algorithm program that reads text file and gives output txt file? This assignment uses C or C++ This assignment involves Banker's Alogrithm. The program must be named "banker" and will read the allocation, max, available, and request vectors from a file. The name of the file will be passed to your program as a command line argument.

The input file format is the following:

- number of processes: n -

number of resource types: m -

An n x m allocation matrix -

An n x m max matrix -

A 1 x m available vector -

A i : 1 x m request vector

Program will output the following in a standardized format.

- Echo the number of processes.

- Echo the number of resource types.

- Echo the allocation matrix. Label the processes and resource types (see sample output).

- Echo the max matrix. Label the processes and resource types (see sample output).

- Compute and print the need matrix. Label the processes and resource types (see sample output).

- Echo the available vector. Label the resource types.

- Compute if the system is in a safe state.

- Echo the request vector. Label the process making the request and resource types (see sample output).

- Compute if the request can be granted.

- Compute the new available vector (see sample output).

SAMPLE INPUT FILE ------------------------------------------------------

5

4

0 0 1 2

1 0 0 0

1 3 5 4

0 6 3 2

0 0 1 4

0 0 1 2

1 7 5 0

2 3 5 6

0 6 5 2

0 6 5 6

1 5 2 0

1:0 4 2 0

---------------------------------------------------------------------- SAMPLE OUTPUT FILE ------------------------------------------------------------- There are 5 processes in the system.

There are 4 resource types.

The Allocation Matrix is...

A B C D

0: 0 0 1 2

1: 1 0 0 0

2: 1 3 5 4

3: 0 6 3 2

4: 0 0 1 4

The Max Matrix is...

A B C D

0: 0 0 1 2

1: 1 7 5 0

2: 2 3 5 6

3: 0 6 5 2

4: 0 6 5 6

The Need Matrix is...

A B C D

0: 0 0 0 0

1: 0 7 5 0

2: 1 0 0 2

3: 0 0 2 0

4: 0 6 4 2

The Available Vector is...

A B C D

1 5 2 0

THE SYSTEM IS IN A SAFE STATE!

The Request Vector is...

A B C D

1:0 4 2 0

THE REQUEST CAN BE GRANTED!

The Available Vector is...

A B C D

1 1 0 0

------------------------------------------------------- This is how the program should be run:

% banker s1.txt

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 Databases Questions!