Presentation on theme: "Rensselaer Polytechnic Institute CSC 432 – Operating Systems David Goldschmidt, Ph.D."— Presentation transcript:
Rensselaer Polytechnic Institute CSC 432 – Operating Systems David Goldschmidt, Ph.D.
The short-term scheduler decides which process the CPU executes next The dispatcher gives control of the CPU to the process selected by the CPU scheduler: Performs context switch Switches to user mode Jumps to the proper location in the user program to resume program execution
CPU scheduling requires an algorithm to determine which process to dispatch next Scheduling algorithms include: First-Come, First-Served (FCFS) Shortest-Job-First (SJF) Round-Robin (RR) Priority Multilevel Queue (MQ)
Preemptive scheduling preempts a running process before its time slice expires Or it preempts a process because its time slice has expired Non-preemptive scheduling gives a process exclusive uninterrupted access to the CPU for the entirety of its execution process
Compare scheduling algorithms by measuring CPU utilization – keep CPU as busy as possible Throughput – maximize the number of processes that complete their execution per unit time Turnaround time – minimize the elapsed time to fully execute a particular process Waiting time – minimize the elapsed time a process waits in the ready queue
FCFS dispatches processes in the order they enter the ready queue FCFS is non-preemptive time P1P1 P2P2 P3P3 2427300 ProcessCPU Burst Time P1P1 24 ms P2P2 3 ms P3P3
SJF dispatches processes by selecting the process with the lowest CPU burst time SJF is non-preemptive (and predictive) time ProcessCPU Burst Time P1P1 24 ms P2P2 3 ms P3P3 P1P1 P3P3 P2P2 63300
What happens when processes arrive at different arrival times? Calculate the turnaround times and wait times for each process Calculate the average turnaround time and average wait time ProcessArrival TimeCPU Burst Time P1P1 07 ms P2P2 2 ms4 ms P3P3 1 ms P4P4 5 ms4 ms
Same as SJF, but a new process may preempt the running process time ProcessArrival TimeCPU Burst Time P1P1 07 ms P2P2 2 ms4 ms P3P3 1 ms P4P4 5 ms4 ms P1P1 P3P3 P2P2 42 11 0 P4P4 57 P2P2 P1P1 16
SJF is the optimal solution The problem with SJF is the inability to know the required CPU burst times Apply a prediction algorithm that uses previous CPU burst times Algorithm uses exponential averaging: ▪ t n = actual length of the nth CPU burst ▪ τ n+1 = predicted value for the next CPU burst ▪ τ n+1 = α t n + (1 – α) τ n, where 0 < α < 1
Apply the FCFS, SJF, and Preemptive SJF scheduling algorithms to this table: Calculate the wait and turnaround times of each process, as well as overall averages ProcessArrival TimeCPU Burst Time P1P1 045 ms P2P2 05 ms P3P3 20 ms15 ms P4P4 60 ms25 ms recalculate using context switch time t cs = 20 μs recalculate using context switch time t cs = 20 μs
Your consent to our cookies if you continue to use this website.