Question
Write a C++ program which reads in a list of process names and integer times from stdin/cin and simulates round-robin CPU scheduling on the list.
Write a C++ program which reads in a list of process names and integer times from stdin/cin and simulates round-robin CPU scheduling on the list. Name the source file assign2.cpp. The input to the program is a list of lines each consisting of a process name and an integer time, e.g.
ProcessA 4 ProcessB 10
Read the list (without prompting) until end of transmission, EOF(^d). You should read the list and represent it in a linked list data structure. You are allowed to use STL classes, BUT DO NOT USE a vector. You should use the alarm system call to schedule a timer interrupt every 3 seconds and sleep (or usleep) to simulate the process running. Use time remaining on the process for the call to sleep. It's easiest if the interrupt handler sets a flag. A process with remaining time will be awakened in the alarm handler. If the quantum is the same or less than remaining time, it will wake up without the alarm. Upon returning from either sleep or the interrupt handler, update the time left by subtracting 3 seconds or the time remaining, depending if interrupted or not. Write a message saying how much time it has left to execute, i.e.
ProcessA 1
If the time remaining is greater than 0, return it to the end of the queue. If the process has no time left to execute, you should write a message saying this i.e.
ProcessA Finished
and delete the process from the linked list. If there are no processes left to execute, write a message saying
No processes left
and terminate your program. Please following the specification EXACTLY.
Running the program/ Expected Output:
[a@edu assign2]$ assign2 ProcessA 9 ProcessB 5 ProcessC 2 ProcessD 8 ProcessE 11 ProcessF 3 ProcessG 7 ProcessH 4 ^d ProcessA 6 ProcessB 2 ProcessC Finished ProcessD 5 ProcessE 8 ProcessF Finished ProcessG 4 ProcessH 1 ProcessA 3 ProcessB Finished ProcessD 2 ProcessE 5 ProcessG 1 ProcessH Finished ProcessA Finished ProcessD Finished ProcessE 2 ProcessG Finished ProcessE Finished No processes left [a@edu assign2]$
Compilation Errors
If you experience compilation errors because alarm, signal, are unrecognized, you probably have left out an include file. Feel free to google or use the man command (i.e. man 3 exec) to see what include files are needed.
#include#include #include
#include #include #include
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started