Need help trying to implement a CPU scheduling algorithm.I am not even sure where to start on this. Can someone please guide me and walk me through the steps for this?
Assignment: The Simulation. Simulating the scheduling of a single CPU is a type of discrete event simulation in which you iterate over discrete steps of time and handle events as they occur. The simulation continues for a given amount of time or until all data has been processed. Add the processes to the ready queue. cpu = None curTime = 0 while ready queue is not empty : handle events that occur during the current time step curTime = curTime + 1 For this project, the simulation will continue while there are still processes that need to use the CPU. There are three types of events that can occur: the CPU is initially empty, the time slice for the current process on the CPU has expired or the process has completed execution before the time slice has expired. • If the CPU is initially empty, select the next process from the ready queue and assign it to the CPU. 1 CS 112 – Spring 2015 Programming Assignment Four – 2 • If a process completes execution, it’s removed from the system and it’s total wait time is added to a running total. • If a process has used its time slice, the process is removed from the CPU and the next process is selected from the ready queue and assigned to the CPU. The process that was removed is added back to the ready queue to wait its turn before it can again use the CPU. Note that the next process has to be dequeued before the current process is added back to the queue. Text File. The simulation data will be contained in a text file that has the following format: 2 15 8 35 0 25 10 5 5 5 2 7 12 30 7 10 0 3 8 15 where each line contains information for a single process. The first value is the priority and the second value is the amount of processing time required (i.e. the total amount of time the processor needs to use the CPU). Note that the lower the priority value, the higher the priority. Assume the first line contains the information for process 1, the second line for process 2, and so on. The Algorithms. You are to implement two priority based scheduling algorithms. For the first algorithm, the next process selected from the ready queue is simply the one with the highest priority. For the second algorithm, you are to make a slight modification. Each time a process is put back into the ready queue, after being removed from the CPU, reduce the priority level by 5. Results. Your program should produce output similar to the following: Number of processes: 10 Time slice: 10 Total time: 150 Algorithm 1 Avg wait time: 60.10 Algorithm 2 Avg wait time: 62.80 To compute the average wait time over all of the processes, you will need to keep track of how much time each process spends in the ready queue and then compute the average of those times. Assume that all processes are started at the exact same time. CS 112 – Spring 2015 Programming Assignment Four – 3 Requirements. Your program should be placed within a driver named cpu.py. Your program should be well structured and commented appropriately as indicated in the programming style guide provided on the course web page. Some important points to keep in mind: • A linked list implementation of the Priority Queue ADT is provided in the course directory. • You must use a top-down design with functions. • Your program should read from the user the name of the text file that contains the simulation data and the length of a time slice (as an integer). • Use a variable (cpu) to hold a reference to the process object (your storage object) for the process that is currently assigned to the cpu. • In addition to the curTime variable, you should use a second time variable that indicates the time when a process needs to be switched off the cpu. This variable acts as an alarm or the time an alarm goes off to signal an event. When a process is assigned to the cpu, compute the time when it should be switched off (current time + time slice or current time + time remaining for the process). • To compute the wait time, you will need to keep track of the current time when the process is added to the ready queue. Then each time a process is removed from the ready queue, compute how much time it spent in the queue and add that to the processes total wait time. • You will need to use a storage object to store the information for a single process. It should contain the process number, the priority, the remaining CPU time required for that process, its total wait time, and the time it was added to the ready queue. The data in the storage object must be stored as integer values. • Each time the process is added back to the ready queue, you should add the storage objects to the priority queue and update the remaining CPU time _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor