CS340d: Operating Systems L. Maram AlShablan CPU scheduling Exercises Princess Noura bint...

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

Transcript of CS340d: Operating Systems L. Maram AlShablan CPU scheduling Exercises Princess Noura bint...

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

CS340d: Operating Systems

L. Maram AlShablan

CPU schedulingExercises

Princess Noura bint Abdulrahman

University

Faculty of Computer and Information

Sciences

Computer science Dept.

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

2

CPU SchedulingExercises from textbook

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

3

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.

From Textbook

L. Maram AlShablan

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

4

What is the average turnaround time for these processes with the FCFS scheduling algorithm?

P1 P2 P3

8 12 130

Waiting time for P1 = 0Waiting time for P2 = 8 - 0.4 =7.6Waiting time for P3 = 12 -1=11 Average turnaround time= (8+4+1+7.6+11)/3 = 10.53 ms

6.3( a)From Textbook

L. Maram AlShablan

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

5

What is the average turnaround time for these processes with theSJF scheduling algorithm?

P1 P3 P2

8 9 130

Waiting time for P1 = 0Waiting time for P2 = 9 - 0.4 =8.6Waiting time for P3 = 8 - 1 =9 Average turnaround time= (8+4+1+8.6+9)/3 = 9.53 ms

6.3( b)From Textbook

L. Maram AlShablan

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

6

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.

From Textbook

L. Maram AlShablan

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

7

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.

P1P3 P2

2 6 141

Waiting time for P1 = 6Waiting time for P2 = 1.6Waiting time for P3 = 0 Average turnaround time= 20.6/3 = 6.86 ms

6.3( C)

This algorithm called future-

knowledge scheduling.

From Textbook

L. Maram AlShablan

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

8

6.16Consider 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.

From Textbook

L. Maram AlShablan

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

9

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 P3P2

2 110 3

P4

15 20

P5

From Textbook

L. Maram AlShablan

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

10

6.16( a)

The Gantt Chart for SJF:

The Gantt Chart for nonpreemptive priority :

P1P2

1 70 3 12

P3

20

P4 P5

P3 P1P5

8 150

P4

20

P2

13 19

From Textbook

L. Maram AlShablan

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

11

6.16( a)

The Gantt Chart for RR (quantum = 2):

P3P1 P5P4P2 P3 P3 P3P5

P4 P5

0 2 3 5 7 9 11 13 15 17 18 20

From Textbook

L. Maram AlShablan

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

12

Time Quantum and Context Switch Time in RR scheduling algorithm

L. Maram AlShablan

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

13

SJF SchedulingExtra Examples

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

14

Draw Gantt charts that illustrate the execution of these processes using the following scheduling algorithms: Non-preemptive SJFPreemptive SJF

L. Maram AlShablan

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

15

Non-preemptive SJF

L. Maram AlShablan

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

16

Preemptive SJF

L. Maram AlShablan

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

17

Thank you

L. Maram AlShablan