cs340d: operating systems l. maram alshablan cpu scheduling exercises princess noura bint...
TRANSCRIPT
![Page 1: CS340d: Operating Systems L. Maram AlShablan CPU scheduling Exercises Princess Noura bint Abdulrahman University Faculty of Computer and Information Sciences](https://reader038.vdocument.in/reader038/viewer/2022102809/5697c00e1a28abf838cc9ad4/html5/thumbnails/1.jpg)
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](https://reader038.vdocument.in/reader038/viewer/2022102809/5697c00e1a28abf838cc9ad4/html5/thumbnails/2.jpg)
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](https://reader038.vdocument.in/reader038/viewer/2022102809/5697c00e1a28abf838cc9ad4/html5/thumbnails/3.jpg)
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](https://reader038.vdocument.in/reader038/viewer/2022102809/5697c00e1a28abf838cc9ad4/html5/thumbnails/4.jpg)
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](https://reader038.vdocument.in/reader038/viewer/2022102809/5697c00e1a28abf838cc9ad4/html5/thumbnails/5.jpg)
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](https://reader038.vdocument.in/reader038/viewer/2022102809/5697c00e1a28abf838cc9ad4/html5/thumbnails/6.jpg)
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](https://reader038.vdocument.in/reader038/viewer/2022102809/5697c00e1a28abf838cc9ad4/html5/thumbnails/7.jpg)
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](https://reader038.vdocument.in/reader038/viewer/2022102809/5697c00e1a28abf838cc9ad4/html5/thumbnails/8.jpg)
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](https://reader038.vdocument.in/reader038/viewer/2022102809/5697c00e1a28abf838cc9ad4/html5/thumbnails/9.jpg)
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](https://reader038.vdocument.in/reader038/viewer/2022102809/5697c00e1a28abf838cc9ad4/html5/thumbnails/10.jpg)
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](https://reader038.vdocument.in/reader038/viewer/2022102809/5697c00e1a28abf838cc9ad4/html5/thumbnails/11.jpg)
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](https://reader038.vdocument.in/reader038/viewer/2022102809/5697c00e1a28abf838cc9ad4/html5/thumbnails/12.jpg)
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](https://reader038.vdocument.in/reader038/viewer/2022102809/5697c00e1a28abf838cc9ad4/html5/thumbnails/13.jpg)
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](https://reader038.vdocument.in/reader038/viewer/2022102809/5697c00e1a28abf838cc9ad4/html5/thumbnails/14.jpg)
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](https://reader038.vdocument.in/reader038/viewer/2022102809/5697c00e1a28abf838cc9ad4/html5/thumbnails/15.jpg)
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](https://reader038.vdocument.in/reader038/viewer/2022102809/5697c00e1a28abf838cc9ad4/html5/thumbnails/16.jpg)
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](https://reader038.vdocument.in/reader038/viewer/2022102809/5697c00e1a28abf838cc9ad4/html5/thumbnails/17.jpg)
17
Thank you
L. Maram AlShablan