CPU Sheduling

2,430 views

Published on

Published in: Technology
2 Comments
2 Likes
Statistics
Notes
No Downloads
Views
Total views
2,430
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
63
Comments
2
Likes
2
Embeds 0
No embeds

No notes for slide

CPU Sheduling

  1. 1. CPU Scheduling<br />Prof.PrasadSawant<br />Lecturer MCA<br />MACS College Pune<br />Operating System Concepts Prasad Sawant<br />
  2. 2. Alternating Sequence of CPU And I/O Bursts<br />Operating System Concepts Prasad Sawant<br />
  3. 3. CPU Scheduler<br />Selects from among the processes in memory that are ready to execute, and allocates the CPU to one of them.<br />CPU scheduling decisions may take place when a process:<br />1. Switches from running to waiting state.<br />2. Switches from running to ready state.<br />3. Switches from waiting to ready.<br />4. Terminates.<br />Scheduling under 1 and 4 is nonpreemptive.<br />All other scheduling is preemptive.<br />Operating System Concepts Prasad Sawant<br />
  4. 4. Dispatcher<br />Dispatcher module gives control of the CPU to the process selected by the short-term scheduler.<br />Operating System Concepts Prasad Sawant<br />
  5. 5. Scheduling Criteria<br />CPU utilization – keep the CPU as busy as possible<br />Throughput– # of processes that complete their execution per time unit<br />Turnaround time – amount of time to execute a particular process<br />Waiting time – amount of time a process has been waiting in the ready queue<br />Operating System Concepts Prasad Sawant<br />
  6. 6. Keep in mind <br />Waiting time (WT)=start time(ST)-Arrival time (AT)<br />Finish time (FT)=start time(ST)+Burst Time(BT)<br />Total turn around time(TOT)=Finish time(FT)-Arrival time (AT )<br />Operating System Concepts Prasad Sawant<br />
  7. 7. Optimization Criteria<br />Max CPU utilization<br />Max throughput<br />Min turnaround time <br />Min waiting time <br />Min response time<br />Operating System Concepts Prasad Sawant<br />
  8. 8. First-Come, First-Served (FCFS) Scheduling<br />Operating System Concepts Prasad Sawant<br />Suppose that the processes arrive in the order: P1 , P2 , P3 <br />schedule<br />schedule<br /> 0 10 20 30 <br />schedule<br />Waiting time for P1 = 0; P2 = 24; P3 = 27<br />Average waiting time: (0 + 24 + 27)/3 = 17<br />P3 30 <br />P2 27 <br />P1 24<br />
  9. 9. First-Come, First-Served (FCFS) Scheduling Gantt Chart<br />Operating System Concepts Prasad Sawant<br />Suppose that the processes arrive in the order: P1 , P2 , P3 <br />schedule<br />schedule<br />schedule<br />Waiting time for P1 = 0; P2 = 24; P3 = 27<br />Average waiting time: (0 + 24 + 27)/3 = 17<br />0 P1 24<br />P2 27<br />P3 30 <br />
  10. 10. Exercise <br />Find Average waiting time for <br />Suppose that the processes arrive in the order: P2 , P3 , P1<br />Operating System Concepts Prasad Sawant<br />
  11. 11. Shortest-Job-First (SJR) Scheduling<br />Associate with each process the length of its next CPU burst. Use these lengths to schedule the process with the shortest time.<br />Two schemes: <br />nonpreemptive – once CPU given to the process it cannot be preempted until completes its CPU burst.<br />preemptive – if a new process arrives with CPU burst length less than remaining time of current executing process, preempt. This scheme is know as the Shortest-Remaining-Time-First (SRTF).<br />SJF is optimal – gives minimum average waiting time for a given set of processes.<br />Operating System Concepts Prasad Sawant<br />
  12. 12. Example of Non-Preemptive SJF<br />Operating System Concepts Prasad Sawant<br />schedule<br />schedule<br />schedule<br />schedule<br />0 P1 7<br />P3 8<br />P2 12<br />P4 16<br />Average waiting time = (0+6+3+7)/4=4<br />
  13. 13. Example of Non-Preemptive SJF<br />Operating System Concepts Prasad Sawant<br />P1 7<br />P3 8<br />P2 12<br />P4 16<br />Average waiting time = (0+6+3+7)/4=4 <br />Average TOT =(7+10+4+11)/4=8<br />
  14. 14. Preemptive SJF<br />Operating System Concepts Prasad Sawant<br />7<br />P<br />schedule<br />10<br />10-1=9<br />schedule<br />1<br />1-1=0<br />schedule<br />17<br />17-2=15<br />schedule<br />5<br />5-3=2<br />0 P1 1<br />P2 5 <br />P4 10<br />P1 17<br />P3 26<br />
  15. 15. Priority Scheduling<br />Operating System Concepts Prasad Sawant<br />Schedule <br />6<br />6<br />Schedule <br />0<br />0<br />Schedule <br />16<br />16<br />Schedule <br />18<br />18<br />Schedule <br />1<br />1<br />41/5=8.2 ms<br />0 P2 1<br />P5 6<br />P1 16<br />P3 18<br />P4 19<br />0<br />
  16. 16. SJF Preemptive Priority Scheduling <br />Operating System Concepts Prasad Sawant<br />P<br />5<br />scheduled<br />19<br />19-3=16<br />scheduled<br />24<br />24-1=23<br />scheduled<br />12<br />12-3=9<br />scheduled<br />3<br />3-3=0<br />48/4=12 ms<br />0 P1 3 <br />P4 12 <br />P3 19<br />P1 24<br />P2 30<br />
  17. 17. Round Robin Scheduling <br />Each process gets a small unit of CPU time (time quantum), usually 10-100 milliseconds. After this time has elapsed, the process is preempted and added to the end of the ready queue.<br />If there are n processes in the ready queue and the time quantum is q, then each process gets 1/nof the CPU time in chunks of at most q time units at once. No process waits more than (n-1)q time units.<br />Operating System Concepts Prasad Sawant<br />
  18. 18. Time Quantum and Context Switch Time <br />Operating System Concepts Prasad Sawant<br />0<br />0 10<br />1<br />6<br /> 10<br />9<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />1<br />
  19. 19. Round Robin Time Quantum 4<br />Operating System Concepts Prasad Sawant<br />24-4=20<br />20-4=16<br />16-4=12<br />12-4=8<br />8-4=4<br />4-4=0<br />scheduled<br />30<br />scheduled<br />7<br />scheduled<br />10<br />0 P1 4 <br />P2 7 <br />P3 10 <br />P1 14 <br />P1 18 <br />P1 22 <br />P1 26 <br />P1 30 <br />
  20. 20. Questions <br />Define the difference between pre-emptive and non-pre-emptive scheduling. <br />Explain the concept of a priority used in scheduling. Why is priority working usually chosen for real time processes?<br />Define by difference between preemptive and non-emptive scheduling.<br />Comment on the principle disadvantage of each of these scheduling methods: FCFS, SJF, RR<br />Operating System Concepts Prasad Sawant<br />
  21. 21. Bibliography <br />Operating System Principle-Peter Galvin Galvin <br />Prof.S.G.Lakhdive<br />(Dept .Computer Sci )<br />Prof.Ramkirshna More A.C.S College Akurdi<br />Mr. AbhishekNagar <br />Web Administrator at Symbiois<br />Operating System Concepts Prasad Sawant<br />
  22. 22. Thanks you <br />Operating System Concepts Prasad Sawant<br />

×