Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

I NEED CODE IN C++ FOR THE DESCRIPTION BELOW. 1. Read the input file line by line and parse each line to separate the resource

I NEED CODE IN C++ FOR THE DESCRIPTION BELOW.

1. Read the input file line by line and parse each line to separate the resource class (e.g. INTERACTIVE, REAL-TIME, CPU, TTY, DISK) and the corresponding time value.

2. Create separate ready queues for REAL-TIME and INTERACTIVE processes and initialize the CPU, TTY and DISK resource states as not busy.

3. Start the simulation with the first process and initialize the simulation clock with the start time of the first process.

4. At each step, check the ready queue for the next process to execute based on priority of REAL-TIME processes and current resource states.

5. If the next process is a REAL-TIME process, assign the CPU to it and check if its deadline has passed. If its deadline has passed, terminate the process and print the process details.

6. If the next process is an INTERACTIVE process, assign the CPU to it and allocate TTY and DISK resources in FCFS order.

7. If the CPU is not busy, allocate it to the next process in the ready queue.

8. Keep track of the resource states and the waiting time for each resource and update the simulation clock at each step.

9. Repeat the above steps until all processes have completed.

10. After all processes have completed, calculate and print the summary report with the number of REAL-TIME and INTERACTIVE processes completed, the percentage of REAL-TIME processes that missed their deadline, the number of disk accesses, the average duration of a disk access, the total time elapsed and the CPU and disk utilizations.

11. This should give you a basic idea of how to approach this problem. You can use arrays and structures to store the process and resource information, and write functions to perform the various operations like resource allocation, process termination, and summary calculation.

THE FULL ASSIGNMENT IS BELOW

1. Objective

This assignment will introduce you to CPU scheduling.

2. Specifications

You are to simulate the execution of processes by a computer system with a large memory, one terminal per user, a CPU, and one disk drive. Each process will be described by its class (REAL-TIME or INTERACTIVE) and its start time followed by a sequence of resource requests.

These resources requests will include CPU requests (CPU), disk reads (DISK) and terminal accesses (TTY). In addition, all real-time processes will have a DEADLINE, by which they must complete.

Your input will be a sequence of pairs as in:

INTERACTIVE 12000 // new process CPU 100 TTY 5000 CPU 100 DISK 10 CPU 20 REAL-TIME 12000 // new process DEADLINE 13000 // absolute time CPU 30 ...

All time will be expressed in milliseconds.

Your program should maintain separate ready queues for real-time and interactive processes and give absolute priority to real-time processes over interactive processes:

Your scheduler should never allocate the CPU to an interactive process as long as there are one or more real-time processes in the ready state.

When a real-time process returns to the ready queue and finds that the CPU is currently allocated to an interactive process, the scheduler should take the CPU away from the interactive process and give it to the real-time process. The pre-empted process should return to the end of the ready queue for interactive processes. When this is the case your program should update the duration of the CPU request by subtracting from the original duration the time the process has already spent in the running state.

Disk scheduling will be strictly first-come first-served (FCFS) without any distinction of process classes.

To simplify your life, we will also assume that:

there is enough memory space for all processes,

context switch times can be neglected,

user think times are included in the terminal access times, and

each process reads and writes to a different terminal.

Your program should read its input file name through input redirection as in:

./a.out < input.txt

If by accident, two resources allocations need to be made at the same time, you should allocate the CPU first then the disk and then the terminals.

Your program should have one process table with one entry per process containing a process sequence number, the process class, its process arrival time and its current status (READY, RUNNING, WAITING).

It should print out one line of output every time a process starts or terminates. This line should include the process sequence number, its class and the current simulated time in milliseconds.

When all the processes in your input stream have completed, your simulator should print a summary report listing:

a) the number of real-time processes that have completed,

b) the percentage of real-time processes that missed their deadline,

c) the number of interactive processes that have completed,

d) the total number of disk accesses,

e) the average duration of a disk access (including the waiting time in the disk queue),

f) the total time elapsed since the start of the first process,

g) the CPU and disk utilizations, that is, the fraction of time the CPU or the disk was busy.

3. Important

Your program should start by a block of comments containing your name, the course number, the due date and a very short description of the assignment. It should contain functions and these functions should have arguments.

Each function should start by a very brief description of the task it performs. Each variable definition should be followed by a comment describing the function of the variable.

All numerical constants should be specified using symbolic constants defined at the beginning of the program.

All the source code files, executable code files, readme files, and all the documentation should submitted electronically through BrightSpace.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image
Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students explore these related Databases questions