2.4. Cpu Scheduling
2.4. Cpu Scheduling
4 CPU scheduling
Disk Memory
Swap a Process
process
Job (input) from ready
to job queue
Queue
Medium Term
02/04/2025
Scheduler Bahir Dar University OS(CoSc2034) 6
Degree of multi-programming is the number of processes
that are placed in the ready queue waiting for execution
by the CPU.
Process 1
Process 2
Process 3 Degree of
Process 4 Multi-Programming
Process 5
Memory
Long Term
Process 1
Disk Scheduler Process 2
Process 3 Degree of
Process 4 Multi-Programming
Process 5
Memory
Job Queue
Medium Term
Process 1
Disk Scheduler Process 2
Process 3 Degree of
Process 4 Multi-Programming
Process 5
Memory
Job Queue
CPU
Non- Preemptive
Scheduling
CPU
02/04/2025 Bahir Dar University OS(CoSc 13
2034)
CPU
Scheduling
CPU utilization range from 40% (for lightly loaded systems) to 90% (for
heavily loaded) (Explain why? CPU utilization can not reach 100%,
because of the context switch between active processes).
Turnaround time:
For a particular process, it is the total time needed for process execution
(from the time of submission to the time of completion).
It is the sum of process execution time and its waiting times (to get memory,
perform I/O, ….).
Waiting time:
The waiting time for a specific process is the sum of all periods it spends
waiting in the ready queue.
Response time.
It is the time from the submission of a process until the first response is
produced (the time the process takes to start responding).
Maximize:
CPU utilization.
System throughput.
Minimize:
Turnaround time.
Waiting time.
Response time.
Ready queue
FCFS Scheduling
CPU
Gant chart:
22 3 P3
Gant chart:
10 5 18 7
X
18 10 7 5
CPU
Note: numbers indicates the
02/04/2025 process
Bahir Dar University execution time
OS(CoSc 23
2034)
Consider the following set of processes, with the length of the CPU burst time
given in milliseconds:
Burst Time Process
The processes arrive in the order 6 P1
P1, P2, P3, P4. All at time 0. 8 P2
7 P3
3 P4
1. Using FCFS
Gant chart:
Hence, average
25 waiting time= (3+16+9+0)/4=7 milliseconds
Bahir Dar University
02/04/2025
OS(CoSc2034)
Shortest-Remaining-Time-First (SRTF)
It is a preemptive version of the Shortest Job First
It allows a new process to gain the processor if its execution
time less than the remaining time of the currently processing
one.
When a new job arrives, its total time is compared to the
current process' remaining time.
If the new job needs less time to finish than the current process,
the current process is suspended and the new job started
SRTF Scheduling
2 10 7 5 3
4
CPU
1. Using SJF
Gant chart:
Hence, average
28 waiting time= (9+1+0+2)/4=3 milliseconds
Bahir Dar University
02/04/2025
OS(CoSc2034)
Round Robin scheduling
• Is one of the oldest, simplest, fairest, and most widely used
algorithms.
Allocate the CPU for one Quantum time (also called time slice)
Q to each process in the ready queue.
If the process has blocked or finished before the quantum has
elapsed, the CPU switching is done when the process blocks, of
course.
This scheme is repeated until all processes are finished.
A new process is added to the end of the ready queue.
setting the quantum too short causes too many process
switches and lowers the CPU efficiency, but setting it too long
may cause poor response to short interactive requests.
Q Q
Q Q
CPU
02/04/2025 Bahir Dar University OS(CoSc 30
2034)
Consider the following set of processes, with the length of the CPU burst time given in
milliseconds:
Burst Time Process
The processes arrive in the order 24 P1
P1, P2, P3. All at time 0.
3 P2
use RR scheduling with Q=2 and Q=4
3 P3
RR with Q=4
Gant chart:
Gant chart:
Hence, average
32 waiting time= (6+6+7)/3=6.33 milliseconds
Bahir Dar University
02/04/2025
OS(CoSc2034)
Explain why? If the quantum time decrease, this will slow down
the execution of the processes.
Sol:
Priority Scheduling
10 5 18 7
X
18 10 7 5
CPU
Note:
02/04/2025 numbers indicates the
Bahir Dar process priority
University OS(CoSc 34
2034)
Problems with Priority scheduling
Very lowVery
priority
low process
priority process
8 28
26 30
8 5 4 2
Starvation
Aging
02/04/2025 Bahir Dar University OS(CoSc 35
2034)
Consider the following set of processes, with the length of the CPU burst time
given in milliseconds:
priority Burst Time Process
3 10 P1
The processes arrive in the order
1 1 P2
P1, P2, P3, P4, P5. All at time 0.
4 2 P3
5 1 P4
2 5 P5
1. Using priority scheduling
Gant chart:
Queue 0
Queue 1
Queue 2