Operating Systems Lecture 15
© Copyright Virtual University of Pakistan Agenda for Today Review of previous lecture Shortest-job-first Round-Robin scheduling Multi-level queues scheduling Multi-level feedback queues scheduling Recap of lecture 21 November 2018 © Copyright Virtual University of Pakistan
© Copyright Virtual University of Pakistan Review of Lecture 14 Short-term scheduler Dispatcher Reasons for invoking scheduler Preemptive and non-preemptive schedulers Optimization criteria FCFS 21 November 2018 © Copyright Virtual University of Pakistan
Shortest-Job-First (SJF) Scheduling Process with the shortest CPU burst is scheduled first. Non-preemptive – once CPU given to a process it cannot be preempted until completes its CPU burst. 21 November 2018 © Copyright Virtual University of Pakistan
Shortest-Job-First (SJF) Scheduling Preemptive – if a new process arrives with CPU burst length less than remaining time of current executing process, preempt it—Shortest-Remaining-Time-First (SRTF). SJF is optimal non-preemptive scheduling algorithm – gives minimum average waiting time for a given set of processes. 21 November 2018 © Copyright Virtual University of Pakistan
© Copyright Virtual University of Pakistan Non-Preemptive SJF Process Arrival Time Burst Time P1 0.0 7 P2 2.0 4 P3 4.0 1 P4 5.0 4 Gantt chart Average waiting time = (0+6+3+7)/4 = 4 P1 P3 P2 7 16 P4 12 21 November 2018 © Copyright Virtual University of Pakistan
© Copyright Virtual University of Pakistan Preemptive SJF Process Arrival Time Burst Time P1 0.0 7 P2 2.0 4 P3 4.0 1 P4 5.0 4 Gantt chart Average waiting time = (9 + 1 + 0 +2)/4 = 3 P3 P2 4 2 11 P4 5 7 P1 16 21 November 2018 © Copyright Virtual University of Pakistan
SJF—CPU Burst of a Process Can only estimate the length of the next CPU burst. Can be done by using the length of previous CPU bursts, using exponential averaging. 21 November 2018 © Copyright Virtual University of Pakistan
Exponential Averaging Estimation based on historical data tn = Length of nth CPU burst n+1 = Estimate for n+1st CPU burst , 0 ≤ ≤1 n+1 = tn + (1- ) n 21 November 2018 © Copyright Virtual University of Pakistan
Exponential Averaging Plugging in value for n, we get n+1 = tn + (1- )[tn-1 + (1- )n-1] = tn + (1- )tn-1 + (1- )2n-1 Continuing like this results in n+1 = tn+ (1 - ) tn-1 + … + (1 - )j tn-j + … + (1 - )n+1 0 21 November 2018 © Copyright Virtual University of Pakistan
Exponential Averaging If = 0 n+1 = n Actual previous bursts do not count If = 1 n+1 = tn Estimates do not count 21 November 2018 © Copyright Virtual University of Pakistan
Exponential Averaging Typical value used for is ½. With this value, our n+1st estimate is Hence the name exponential averaging n+1 = tn/2 + tn-1/22 + tn-2/23 + tn-3/24 + … 21 November 2018 © Copyright Virtual University of Pakistan
© Copyright Virtual University of Pakistan Priority Scheduling A priority number (integer) is associated with each process The CPU is allocated to the process with the highest priority (smallest integer highest priority). Preemptive Non-preemptive 21 November 2018 © Copyright Virtual University of Pakistan
© Copyright Virtual University of Pakistan Priority Scheduling SJF is a priority scheduling where priority is the predicted next CPU burst time. Problem Starvation – low priority processes may never execute. Solution Aging – as time progresses increase the priority of the process. 21 November 2018 © Copyright Virtual University of Pakistan
© Copyright Virtual University of Pakistan Recap of Lecture Shortest-Job-First (SJF) Shortest-Remaining-Time-First (SRTF) Exponential averaging Priority scheduling Recap of lecture 21 November 2018 © Copyright Virtual University of Pakistan