CPU Scheduling Algorithm
CPU Scheduling Algorithm
g
Algorithm
s
Group No. 2
Overview
Basic Concepts
Scheduling Criteria
Scheduling Algorithms
Implementation in C++
Demonstration
Basic Concepts
CPU Scheduler
CPU Scheduler
CONT
Nonpreemptive
Once a process is allocated the CPU, it
does not leave unless:
o it has to wait, e.g., for I/O request
o it terminates
Preemptive
o OS can force (preempt) a process
from CPU at anytime
o E.g., to allocate CPU to another
higher-priority process
Scheduling Criteria
CPU
Scheduling Criteria
CONT
Scheduling Algorithms
Priority
Round Robin
Implementation in C++
Class: cpuschedule
Attributes:
o n
number of processes
o Bu[ ] Array to store Burst
Time
o A[ ]
Array to store Arrival
Time
o Wt[ ] Array to store Waiting
Time
o Twt
Total Waiting Time
o Awt
Average Waiting Time
CPU Scheduling Algorithms
CONT
Implementation in C++
Operations
:o
Getdata() To get number of
processes and Burst Times from
the user
o Fcfs() First Come, First Served
Algorithm
o Sjf() Shortest Job First
(normal) Algorithm
o SjfP() Shortest Job First
(Preemption) Algorithm
o SjfNp() Shortest Job First (non
preemption) Algorithm
o Priority() Priority Algorithm
CPU Scheduling Algorithms
10
P2
24
P3
27
30
11
CONT
order :
P2 , P3 , P1 (P1:24,P2:3,P3:3)
P3
P1
30
12
Burst Time
7
P2
P3
P3
3
P1
7
14
13
CONT
Arrival Time
0.0
Burst Time
7
P2
2.0
P3
4.0
P4
5.0
12
16
14
CONT
Burst Time
7
4
1
4
P2
2
Average
P3
4
P2
5
P4
7
P1
11
16
15
CONT
16
Priority
Process
P1
P2
P3
P4
P5
Priority
3
1
4
5
2
Gantt Chart
P2
0
Burst Time
10
1
2
1
5
P5
1
P1
6
P3
16
P4
18
19
Priority
CONT
18
Round Robin
Process
P1
P2
P3
Burst Time
24
3
3
Quantum
time = 4 milliseconds
The Gantt chart is:
P1
0
P2
4
P3
7
P1
10
P1
14
P1
18
P1
22
P1
26
30
Average
19
Round Robin
CONT
20
Involvement of OS
Source Code
Compiler
Conversion
Executable
Microsoft
Windows
Microkernel
(.c)
(.i , .o)
(.exe)
(load executable
directly to memory)
Memory
CP
U
Execut
e
Scheduling
Algorithms
21
CPU
Schedulin
g
Algorithm
Group No.
s
2
Group No. 2
22