One of the main applications of priority queues is in operating systems - for sc
ID: 3651597 • Letter: O
Question
One of the main applications of priority queues is in operating systems - for scheduling jobs on a CPU. Inthis assignment you are to build a program that schedules simulated CPU jobs. Your program should run
in a loop, each iteration of which corresponds to a time slice for the CPU. Each job is assigned a priority,
which is an integer between -20 (highest priority) and 19 (lowest priority), inclusive. From among all jobs
waiting to be processed in a time slice, the CPU must work on a job with highest priority. In this simulation,
each job will also come with a length value, which is an integer between 1 and 10, inclusive, indicating
the number of time slices that are needed to process this job. When not interrupted, a job, when scheduled
on the CPU, runs for a number of time slices equal to its length. Jobs, however, may be preempted. For
example, when a new job with a higher priority arrives, execution of the current job will be suspended, with
the un?nished time-slices as the new job length. For simplicity, overhead from context switches will not be
accounted for. Also, jobs of the same priority are scheduled on a ?rst-come-?rst-served (FCFS) basis.
Your simulator must output the name of the job running on the CPU in each time slice and must process
a sequence of commands, one per time slice, each of which is of the form
Explanation / Answer
#include #include #include #include #include #include using namespace std; typedef unsigned char boolean; //*********************************** // define directives //*********************************** // Directive to store the minimum time slice #define MIN_TIME_SLICE 10 // Directive to store the maximum time slice #define MAX_TIME_SLICE 300 // Directive to store the lowest priority (*note* higher number = lower priority) #define MIN_PRIORITY 140 // Directive to store the highest priority(*note* lower number = higher priority) #define MAX_PRIORITY 100 // Directive to store the highest nice value(*note* lower number = nicer Process) #define MAX_NICE = -20 // Directive to store the lowest nice value (*note* higher number = not so nice Process) #define MIN_NICE = 19 //*********************************** // globals //*********************************** // Clock for my scheduler long myClock; // Max amount of proccess in the file int maxProcesses; // Total turn around time for all Processes long totalTAT; // Total wait time for all Processes long totalWT; // Total CPU utiliation Time for all Processes double totalCUT; // The global count variables that gets used over and over again int i, j, k; // The global temp integer variable int tempInt; // class that defines what a Processes is class ProcessContents{ public: // constructors ProcessContents( ); ProcessContents(ProcessContents*); // values in a process int pid; //pid of Process int nice; // Processes nice value int arrivalTime; // Processes arrival time int numCPUBursts; // number of cpu bursts int numIOBursts; // number of i/o bursts = #cpu bursts - 1 int totalBursts; int endTime; // Processes end time int priority; // priority of Process int timeslice; // Processes timesliceSTRUCT AS A FUNCTION PARAMETER DECLARATION int* burst; // dynamic array of cpu bursts and io bursts for the Process void insert(ProcessContents*); void setData(ProcessContents*); // setters ProcessContents* getPrev(); ProcessContents* getNext(); void setNext(ProcessContents*); ProcessContents getData(); int getDataEl(); void reset(); void prev(); void next(); void end(); //Boolean boolean isBeginning(); boolean isEnd(); boolean isEmpty(); private: ProcessContents *m_next, *m_prev, *m_curr; }; ProcessContents :: ProcessContents() { m_prev = NULL; m_next = NULL; m_curr = this; endTime = 0; priority = 69; timeslice = 143; burst = NULL; } ProcessContents :: ProcessContents(ProcessContents* previous) { m_prev = previous; coutRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.