Computer Operating Systems Lecture 7 PDF

Document Details

Uploaded by Deleted User

Tags

computer operating systems priority scheduling round robin operating systems concepts

Summary

This document is a lecture on computer operating systems, covering various scheduling algorithms such as priority scheduling and round robin. It includes examples and Gantt charts to illustrate the concepts.

Full Transcript

Computer Operating Systems Computer Operating Systems 1 Course Reference  Textbook: A. Silberschatz, P. Galvin, and G. Gagne, Operating Systems Concepts, 10th Edition, Wiley, 2018, ISBN: 978-1-119-32091-3. Computer Operating Systems...

Computer Operating Systems Computer Operating Systems 1 Course Reference  Textbook: A. Silberschatz, P. Galvin, and G. Gagne, Operating Systems Concepts, 10th Edition, Wiley, 2018, ISBN: 978-1-119-32091-3. Computer Operating Systems 2 Priority Scheduling  A priority number (integer) is associated with each process  The CPU is allocated to the process with the highest priority Preemptive Nonpreemptive  Problem ≡ Starvation – low priority processes may never execute  Solution ≡ Aging – as time progresses increase the priority of the process Computer Operating Systems 3 Example of Nonpreemptive Priority Scheduling Process Burst Time Priority P1 10 3 P2 1 1 P3 2 4 P4 1 5 P5 5 2 A smaller priority number implies a higher priority  Priority scheduling Gantt Chart Computer Operating Systems 4 Example of Nonpreemptive Priority Scheduling Process Burst Time Priority P1 10 3 P2 1 1 P3 2 4 P4 1 5 P5 5 2  Priority scheduling Gantt Chart Waiting Time 𝑷𝑷𝟏𝟏 𝑷𝑷𝟐𝟐 𝑷𝑷𝟑𝟑 𝑷𝑷4 𝑷𝑷5  Average waiting time = 8.2 6-0 0-0 16-0 18-0 1-0 Computer Operating Systems 5 Example of Nonpreemptive Priority Scheduling Process Burst Time Priority P1 10 3 P2 1 1 P3 2 4 P4 1 5 P5 5 2  Priority scheduling Gantt Chart Turnaround Time 𝑷𝑷𝟏𝟏 𝑷𝑷𝟐𝟐 𝑷𝑷𝟑𝟑 𝑷𝑷4 𝑷𝑷5  Average turnaround time = 12 16-0 1-0 18-0 19-0 6 -0 Computer Operating Systems 6 Example of Nonpreemptive Priority Scheduling Process Burst Time Priority P1 10 3 P2 1 1 P3 2 4 P4 1 5 P5 5 2  Priority scheduling Gantt Chart Response Time 𝑷𝑷𝟏𝟏 𝑷𝑷𝟐𝟐 𝑷𝑷𝟑𝟑 𝑷𝑷4 𝑷𝑷5  Average response time = 8.2 6-0 0-0 16-0 18-0 1-0 Computer Operating Systems 7 Example of Preemptive Priority Scheduling Process Arrival Time Burst Time Priority P1 0 3 3 P2 1 4 2 P3 2 6 4 P4 3 4 6 P5 5 2 10  Priority scheduling Gantt Chart Computer Operating Systems 8 Example of Preemptive Priority Scheduling Arrival Burst After After After After After After After After After Process Priority Time Time 1 2 3 4 5 7 13 17 19 P1 0 3 3 2 2 2 2 2 - - - - P2 1 4 2 4 3 2 1 - - - - - P3 2 6 4 6 6 6 6 6 - - - P4 3 4 6 4 4 4 4 4 - - P5 5 2 10 2 2 2 2 -  Priority scheduling Gantt Chart P1 P2 P1 P3 P4 P5 0 1 5 7 13 17 19 Computer Operating Systems 9 Example of Preemptive Priority Scheduling Arrival Burst After After After After After After After After After Process Priority Time Time 1ms 2ms 3ms 4ms 5ms 7ms 13ms 17ms 19ms P1 0 3 3 2 2 2 2 2 - - - - P2 1 4 2 4 3 2 1 - - - - - P3 2 6 4 6 6 6 6 6 - - - P4 3 4 6 4 4 4 4 4 - - P5 5 2 10 2 2 2 2 -  Priority scheduling Gantt Chart P1 P2 P1 P3 P4 P5 0 1 5 7 13 17 19 Waiting Time Average Waiting Time = 31/5 = 6.20 𝑷𝑷𝟏𝟏 𝑷𝑷𝟐𝟐 𝑷𝑷𝟑𝟑 𝑷𝑷4 𝑷𝑷5 5-1 0 7-2 13-3 17-5 Computer Operating Systems 10 Example of Preemptive Priority Scheduling Arrival Burst After After After After After After After After After Process Priority Time Time 1ms 2ms 3ms 4ms 5ms 7ms 13ms 17ms 19ms P1 0 3 3 2 2 2 2 2 - - - - P2 1 4 2 4 3 2 1 - - - - - P3 2 6 4 6 6 6 6 6 - - - P4 3 4 6 4 4 4 4 4 - - P5 5 2 10 2 2 2 2 -  Priority scheduling Gantt Chart P1 P2 P1 P3 P4 P5 0 1 5 7 13 17 19 Turnaround Time Average Turnaround Time = 50/5 = 10 𝑷𝑷𝟏𝟏 𝑷𝑷𝟐𝟐 𝑷𝑷𝟑𝟑 𝑷𝑷4 𝑷𝑷5 7-0 5-1 13-2 17-3 19-5 Computer Operating Systems 11 Example of Preemptive Priority Scheduling Arrival Burst After After After After After After After After After Process Priority Time Time 1ms 2ms 3ms 4ms 5ms 7ms 13ms 17ms 19ms P1 0 3 3 2 2 2 2 2 - - - - P2 1 4 2 4 3 2 1 - - - - - P3 2 6 4 6 6 6 6 6 - - - P4 3 4 6 4 4 4 4 4 - - P5 5 2 10 2 2 2 2 -  Priority scheduling Gantt Chart P1 P2 P1 P3 P4 P5 0 1 5 7 13 17 19 Response Time Average Response Time = 27/5 = 5.40 𝑷𝑷𝟏𝟏 𝑷𝑷𝟐𝟐 𝑷𝑷𝟑𝟑 𝑷𝑷4 𝑷𝑷5 0 0 7-2 13-3 17-5 Computer Operating Systems 12 Round Robin (RR)  Each process gets a small unit of CPU time (time quantum q), usually 10-100 milliseconds. After this time has elapsed, the process is preempted and added to the end of the ready queue.  Timer interrupts every quantum to schedule next process  Performance q large ⇒ FCFS q small ⇒ q must be large with respect to context switch time, otherwise overhead is too high Computer Operating Systems 13 Time Quantum and Context Switch Time Computer Operating Systems 14 Example of RR with Time Quantum = 4 Process Burst Time P1 24 P2 3 P3 3  The Gantt chart is: P1 P2 P3 P1 P1 P1 P1 P1 0 4 7 10 14 18 22 26 30  Typically, higher average turnaround than SJF, but better response time.  q should be large compared to context switch time q usually 10 milliseconds to 100 milliseconds Context switch < 10 microseconds Waiting Time 𝑷𝑷𝟏𝟏 𝑷𝑷𝟐𝟐 𝑷𝑷𝟑𝟑  Average waiting time = 5.67 10-4 4 7 Computer Operating Systems 15 Example of RR with Time Quantum = 4 Process Burst Time P1 24 P2 3 P3 3  The Gantt chart is: P1 P2 P3 P1 P1 P1 P1 P1 0 4 7 10 14 18 22 26 30 Turnaround Time 𝑷𝑷𝟏𝟏 𝑷𝑷𝟐𝟐 𝑷𝑷𝟑𝟑  Average turnaround time = 15.67 30 7 10 Computer Operating Systems 16 Example of RR with Time Quantum = 4 Process Burst Time P1 24 P2 3 P3 3  The Gantt chart is: P1 P2 P3 P1 P1 P1 P1 P1 0 4 7 10 14 18 22 26 30 Response Time 𝑷𝑷𝟏𝟏 𝑷𝑷𝟐𝟐 𝑷𝑷𝟑𝟑  Average response time = 3.67 0 4 7 Computer Operating Systems 17 Multilevel Queue  Ready queue is partitioned into separate queues, eg: foreground (interactive processes) background (batch processes)  Each queue has its own scheduling algorithm: foreground can use RR as an example background can use FCFS as an example  Scheduling must be done between the queues: Fixed priority scheduling; (i.e., serve all from foreground then from background). Possibility of starvation. Time slice – each queue gets a certain amount of CPU time which it can schedule amongst its processes; i.e., 80% to foreground in RR and 20% to background in FCFS Computer Operating Systems 18 Multilevel Queue  Prioritization based upon process type Computer Operating Systems 19 Multilevel Feedback Queue  A process can move between the various queues.  Aging can be implemented using multilevel feedback queue.  The idea is to separate processes according to the characteristics of their CPU bursts. If a process uses too much CPU time, it will be moved to a lower-priority queue. This scheme leaves I/O-bound and interactive processes which are typically characterized by short CPU bursts in the higher-priority queues. A process that waits too long in a lower-priority queue may be moved to a higher-priority queue. This form of aging prevents starvation. Computer Operating Systems 20 Multilevel Feedback Queue  Multilevel-feedback-queue scheduler defined by the following parameters: Number of queues Scheduling algorithms for each queue Method used to determine when to upgrade a process Method used to determine when to demote a process Method used to determine which queue a process will enter when that process needs service Computer Operating Systems 21 Example of Multilevel Feedback Queue  Three queues: Q0 – RR with time quantum 8 milliseconds Q1 – RR time quantum 16 milliseconds Q2 – FCFS  Scheduling A new process enters queue Q0 which is served in RR  When it gains CPU, the process receives 8 milliseconds  If it does not finish in 8 milliseconds, the process is moved to queue Q1 At Q1 job is again served in RR and receives 16 additional milliseconds  If it still does not complete, it is preempted and moved to queue Q2 Computer Operating Systems 22

Use Quizgecko on...
Browser
Browser