Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS340d: Operating Systems

Similar presentations


Presentation on theme: "CS340d: Operating Systems"— Presentation transcript:

1 CS340d: Operating Systems
Princess Noura bint Abdulrahman University Faculty of Computer and Information Sciences Computer science Dept. CS340d: Operating Systems CPU scheduling Exercises L. Maram AlShablan

2 CPU Scheduling Exercises from textbook

3 From Textbook 6.3 Suppose that the following processes arrive for execution at the times indicated. Each process will run for the amount of time listed. In answering the questions, use nonpreemptive scheduling, and base all decisions on the information you have at the time the decision must be made. L. Maram AlShablan

4 From Textbook 6.3 (a) What is the average turnaround time for these processes with the FCFS scheduling algorithm? P1 P2 P3 8 12 13 Waiting time for P1 = 0 Waiting time for P2 = =7.6 Waiting time for P3 = 12 -1=11  Average turnaround time= ( )/3 = ms L. Maram AlShablan

5 From Textbook 6.3 (b) What is the average turnaround time for these processes with the SJF scheduling algorithm? P1 P3 P2 8 9 13 Waiting time for P1 = 0 Waiting time for P2 = =8.6 Waiting time for P3 = =9  Average turnaround time= ( )/3 = 9.53 ms L. Maram AlShablan

6 The SJF algorithm is supposed to improve performance, but notice
From Textbook The SJF algorithm is supposed to improve performance, but notice that we chose to run process P1 at time 0 because we did not know that two shorter processes would arrive soon. L. Maram AlShablan

7 This algorithm called future-knowledge scheduling.
From Textbook 6.3 (C) What the average turnaround time will be if the CPU is left idle for the first 1 unit and then SJF scheduling is used. Remember that processes P1 and P2 are waiting during this idle time, so their waiting time may increase. This algorithm called future-knowledge scheduling. P1 P3 P2 2 6 14 1 Waiting time for P1 = 6 Waiting time for P2 = 1.6 Waiting time for P3 = 0  Average turnaround time= 20.6/3 = 6.86 ms L. Maram AlShablan

8 From Textbook 6.16 Consider the following set of processes, with the length of the CPU burst given in milliseconds: The processes are assumed to have arrived in the order P1, P2, P3, P4, P5, all at time 0. L. Maram AlShablan

9 From Textbook 6.16 (a) Draw four Gantt charts that illustrate the execution of these processes using the following scheduling algorithms: FCFS, SJF, nonpreemptive priority (a larger priority number implies a higher priority), and RR (quantum = 2). The Gantt Chart for FCFS: P1 P3 P2 2 11 3 P4 15 20 P5 L. Maram AlShablan

10 6.16 (a) The Gantt Chart for SJF:
From Textbook 6.16 (a) The Gantt Chart for SJF: P1 P2 1 7 3 12 P3 20 P4 P5 The Gantt Chart for nonpreemptive priority: P3 P1 P5 8 15 P4 20 P2 13 19 L. Maram AlShablan

11 6.16 (a) The Gantt Chart for RR (quantum = 2): From Textbook P1 P2 P3
L. Maram AlShablan

12 Time Quantum and Context Switch Time in RR scheduling algorithm
L. Maram AlShablan

13 SJF Scheduling Extra Examples

14 Draw Gantt charts that illustrate the execution of these processes using the following scheduling algorithms: Non-preemptive SJF Preemptive SJF L. Maram AlShablan

15 Non-preemptive SJF L. Maram AlShablan

16 Preemptive SJF L. Maram AlShablan

17 Thank you L. Maram AlShablan


Download ppt "CS340d: Operating Systems"

Similar presentations


Ads by Google