CS340d: Operating Systems L. Maram AlShablan CPU scheduling Exercises Princess Noura bint...
-
Upload
gavin-stevens -
Category
Documents
-
view
216 -
download
0
Transcript of CS340d: Operating Systems L. Maram AlShablan CPU scheduling Exercises Princess Noura bint...
CS340d: Operating Systems
L. Maram AlShablan
CPU schedulingExercises
Princess Noura bint Abdulrahman
University
Faculty of Computer and Information
Sciences
Computer science Dept.
2
CPU SchedulingExercises from textbook
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
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
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
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
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
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
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
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
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
12
Time Quantum and Context Switch Time in RR scheduling algorithm
L. Maram AlShablan
13
SJF SchedulingExtra Examples
14
Draw Gantt charts that illustrate the execution of these processes using the following scheduling algorithms: Non-preemptive SJFPreemptive SJF
L. Maram AlShablan
15
Non-preemptive SJF
L. Maram AlShablan
16
Preemptive SJF
L. Maram AlShablan
17
Thank you
L. Maram AlShablan