Final Term PPtT 1_ CPU Scheduling
Final Term PPtT 1_ CPU Scheduling
LESSON GUIDE
CPU Scheduling
• Basic Concepts
• Process Schedulers
• Scheduling Criteria
CPU Scheduler
• Long Term Scheduler
• Medium Term Scheduler
• Short Term Scheduler
LESSON GUIDE
CPU Scheduling Algorithm
• First Come First Serve (FCFS)
• Shortest Job First (SJF)
• Shortest Remaining Time First (SRTF)
• Round Robin Scheduling (RR)
• Priority Scheduling (Prio)
• Preemptive Priority Scheduling
(PPrio)
CPU SCHEDULING
It is a fundamental function of an
operating system that manages how
processes are assigned CPU time. The
objective is to optimize CPU utilization
while ensuring that processes are
executed efficiently and fairly.
CPU SCHEDULING
Process Execution Cycle
CPU Burst:
This is the time during which a process is actively executing on the
CPU. CPU bursts can vary significantly between processes based
on their computational requirements.
I/O Burst:
This phase occurs when a process is waiting for I/O operations to
complete, such as reading from disk or waiting for user input.
Typically, I/O bursts are shorter than CPU bursts, and processes
frequently alternate between these two states.
CPU SCHEDULING
Process Execution Cycle
Final CPU Burst:
This refers to the last segment of CPU time required by a process
before it can terminate.
Upon completing this burst, the process releases its resources and
terminates.
CPU SCHEDULING
Basic Concepts
Process State
Context Switching
Time Quantum
Preemptive vs. Non-preemptive
Scheduling
CPU SCHEDULING
Basic Concepts
PROCESS STATE
Each process in an operating system can
be in one of several states, including new,
ready, running, waiting, and terminated.
The scheduler decides which process in
the ready state gets the CPU.
CPU SCHEDULING
Basic Concepts
CONTEXT SWITCHING
This is the process of saving the state of
a currently running process and loading
the state of the next scheduled process. It
incurs overhead, which can affect overall
system performance.
CPU SCHEDULING
Basic Concepts
TIME QUANTUM
In time-sharing systems, a time quantum
defines the maximum time a process can
run before being preempted. This helps
ensure fair CPU time allocation among
processes.
CPU SCHEDULING
Basic Concepts
Preemptive Scheduling: The operating
system can forcibly remove a process
from the CPU to allow another process to
run. This is essential for responsive
systems.
Non-preemptive Scheduling: Once a
process is given the CPU, it runs to
completion or voluntarily yields control.
This can lead to inefficiencies in systems
with varying process requirements.
CPU SCHEDULING
CPU Scheduler and Dispatcher
CPU Scheduler
Dispatch Latency
This term refers to the time taken by the dispatcher to
stop one process and start executing another.
CPU SCHEDULING
EVENT SCHEDULING
CPU scheduling occurs during specific events in a process’s
lifecycle:
CPU Utilization
This measures the percentage of time the CPU is actively working.
High CPU utilization is desirable, as it indicates that the CPU is not
idle.
Throughput
This refers to the number of processes completed per unit of time.
Higher throughput indicates a more efficient system.
CPU SCHEDULING
SCHEDULING EFFICIENCY
Turnaround Time:
This is the total time taken from the submission of a process to its
completion, including waiting, execution, and I/O times.
Waiting Time:
The total time a process spends waiting in the ready queue before
it gets CPU time.
Response Time:
This is the time from when a request is submitted until the first
response is produced. It is particularly important for interactive
processes..
CPU SCHEDULING
CPU SCHEDULING ALOGORITHM
First Come First Serve (FCFS)
FCFS is the simplest CPU scheduling algorithm. Processes are
executed in the order they arrive in the ready queue.
Advantages:
Simple to implement and understand.
Fair in the sense that every process gets served in the order it
arrives.
Disadvantages:
Can lead to the "convoy effect," where short processes wait for
long processes to complete, resulting in high average waiting time.
Not suitable for time-sharing systems where response time is
critical.
CPU SCHEDULING
CPU SCHEDULING ALOGORITHM
Shortest Remaining Time First (SRTF)
SRTF is the preemptive version of SJF. If a new process arrives with a
shorter remaining time than the currently running process, the CPU is
preempted.
Advantages:
Reduces average waiting time and turnaround time compared to SJF.
More responsive for short jobs in interactive environments.
Disadvantages:
Increased overhead due to frequent context switching.
Still suffers from the potential for starvation.
CPU SCHEDULING
CPU SCHEDULING ALOGORITHM
Round Robin Scheduling (RR)
Round Robin scheduling assigns a fixed time slice (quantum) to each
process in the ready queue. If a process does not finish in its allotted
time, it is placed at the end of the queue.
Advantages:
Fair and ensures all processes receive CPU time.
Good for time-sharing systems, providing responsiveness.
Disadvantages:
The performance is heavily dependent on the time quantum size. A
very small quantum can lead to excessive context switching, while a
large quantum can behave like FCFS.
Average waiting time can be higher than SJF or SRTF.
CPU SCHEDULING
CPU SCHEDULING ALOGORITHM
Priority Scheduling (Prio)
Processes are assigned priorities, and the CPU is allocated to the
process with the highest priority. Lower numerical values often denote
higher priority.
Advantages:
Flexible; allows critical processes to be prioritized.
Useful in real-time systems where certain tasks must be completed
promptly.
Disadvantages:
Can lead to starvation if low-priority processes are perpetually
preempted by higher-priority processes.
Implementation complexity increases with dynamic priority changes.
CPU SCHEDULING
CPU SCHEDULING ALOGORITHM
Preemptive Priority Scheduling (PPrio)
This is a preemptive version of priority scheduling. If a new process
arrives with a higher priority than the currently running process, it
preempts the CPU.
Advantages:
Ensures that high-priority tasks are executed immediately, improving
response times for critical tasks.
Reduces the likelihood of starvation with appropriate mechanisms.
Disadvantages:
Increased context switching can lead to overhead.
Complexity in managing priority levels and avoiding starvation.
CPU SCHEDULING
SCHEDULING ALGORITHM
First Come First Serve (FCFS)
Mode:Non-Preemptive / Arrival Time
Queue Arrival Burst Completion Turn Around Time Waiting
Time Time Time (CT-AT) ((TAT-BT)
P1 0 5
P2 1 3
P3 2 8
P4 3 6
P1 P2 P3 P4
0 5 8 16 22
CPU SCHEDULING
SCHEDULING ALGORITHM
First Come First Serve (FCFS)
Mode:Non-Preemptive / Arrival Time
Queue Arrival Burst Completion Turn Around Time Waiting
Time Time Time (CT-AT) ((TAT-BT)
P1 0 5 5 5 0
P2 1 3 8 7 4
P3 2 8 16 14 6
P4 3 6 22 19 13
P1 P2 P3 P4
0 5 8 16 22
CPU SCHEDULING
SCHEDULING ALGORITHM
First Come First Serve (FCFS)
Mode:Non-Preemptive / Arrival Time
Queue Arrival Burst Completi Turn Around Waiting Response
Time Time on Time Time (CT-AT) ((TAT-BT) Time
P1 2 2 4 2 0 0
P2 0 1 1 1 0 0
P3 2 3 7 5 2 2
P4 3 5 12 9 4 4
P5 4 4 16 12 8 8
P2 P1 P3 P4 P5
0 1 2 4 7 12 16
CPU SCHEDULING
SCHEDULING ALGORITHM
First Come First Serve (FCFS)
Mode:Non-Preemptive / Priority Time
Queue Priority Burst Completion Turn Around Time Waiting
Time Time Time (CT-AT) ((TAT-BT)
P1 3 17
P2 2 3
P3 1 6
P4 4 2
P3 P2 P1 P4
0 6 9 26 28
CPU SCHEDULING
SCHEDULING ALGORITHM
First Come First Serve (FCFS)
Mode:Non-Preemptive / Priority Time
Queue Priority Burst Completion Turn Around Time Waiting
Time Time Time (CT-AT) ((TAT-BT)
P1 3 17 26 26 9
P2 2 3 9 9 6
P3 1 6 6 6 0
P4 4 2 28 28 26
P3 P2 P1 P4
0 6 9 26 28
CPU SCHEDULING
SCHEDULING ALGORITHM
Shortest Job First (SJF)
Mode:Non-Preemptive / Burst Time
Queue Arrival Burst Completi Turn Around Waiting Response
Time Time on Time Time (CT-AT) ((TAT-BT) Time
P1 2 1
P2 1 5
P3 4 1
P4 0 6
P5 2 3
P4 P1 P3 P5 P2
0 6 7 8 11 16
CPU SCHEDULING
SCHEDULING ALGORITHM
Shortest Job First (SJF)
Mode:Non-Preemptive / Burst Time
Queue Arrival Burst Completi Turn Around Waiting Response
Time Time on Time Time (CT-AT) ((TAT-BT) Time
P1 2 1 7 5 4 4
P2 1 5 16 15 10 10
P3 4 1 8 4 3 3
P4 0 6 6 6 0 0
P5 2 3 11 9 6 6
P4 P1 P3 P5 P2
0 6 7 8 11 16
CPU SCHEDULING
SCHEDULING ALGORITHM
Shortest Job First (SJF)
Mode:Non-Preemptive / Burst Time
Queue Arrival Burst Completi Turn Around Waiting Response
Time Time on Time Time (CT-AT) ((TAT-BT) Time
P1 0 8
P2 1 4
P3 2 9
P4 3 5
P5 4 6
P1 P2 P4 P5 P3
0 8 12 17 23 32
CPU SCHEDULING
SCHEDULING ALGORITHM
Shortest Job First (SJF)
Mode:Non-Preemptive / Burst Time
Queue Arrival Burst Completi Turn Around Waiting Response
Time Time on Time Time (CT-AT) ((TAT-BT) Time
P1 0 8 8 8 0 0
P2 1 4 12 11 7 7
P3 2 9 32 30 21 21
P4 3 5 17 14 9 9
P5 4 6 23 19 13
P1 P2 P4 P5 P3
0 8 12 17 23 32
CPU SCHEDULING
SCHEDULING ALGORITHM
Shortest Remaining Job First (SRJF)
Mode:Preemptive / Burst Time
Queue Arrival Burst Completion Turn Around Waiting Response
Time Time Time Time (CT-AT) ((TAT-BT) Time
P1 0 8
P2 3 4
P3 4 5
P4 6 3
P5 10 2
P1 P2 P4 P5 P1 P3
0 3 7 10 12 17 22
CPU SCHEDULING
SCHEDULING ALGORITHM
Shortest Remaining Job First (SRJF)
Mode:Preemptive / Burst Time
Queue Arrival Burst Completion Turn Around Waiting Response
Time Time Time Time (CT-AT) ((TAT-BT) Time
P1 0 8
P2 1 1
P3 2 3
P4 3 2
P5 4 6
CPU SCHEDULING
SCHEDULING ALGORITHM
Shortest Remaining Job First (SRJF)
Mode:Preemptive / Burst Time
Queue Arrival Burst Completion Turn Around Waiting Response
Time Time Time Time (CT-AT) ((TAT-BT) Time
P1 0 8 20 20 12 0
P2 1 1 2 1 0 0
P3 2 3 5 3 0 0
P4 3 2 7 4 2 2
P5 4 6 13 9 3 3
CPU SCHEDULING
SCHEDULING ALGORITHM
Shortest Job First (SJF)
Mode:Non-Preemptive / Burst Time
Queue Arrival Burst Completion Turn Around Waiting Response
Time Time Time Time (CT-AT) ((TAT-BT) Time
P1 3 1
P2 1 4
P3 4 2
P4 0 6
P5 2 3
CPU SCHEDULING
SCHEDULING ALGORITHM
Shortest Remaining Job First (SRJF)
Mode:Preemptive / Burst Time
Queue Arrival Burst Completion Turn Around Waiting Response
Time Time Time Time (CT-AT) ((TAT-BT) Time
P1 2 1 3
P2 1 5 16
P3 4 1 5
P4 0 6 11
P5 2 3 7
CPU SCHEDULING
SCHEDULING ALGORITHM
Shortest Remaining Job First (SRJF)
Mode:Preemptive / Burst Time
Queue Arrival Burst Completion Turn Around Waiting Response
Time Time Time Time (CT-AT) ((TAT-BT) Time
P1 0 8
P2 1 4
P3 2 2
P4 3 1
P5 4 3
P6 5 2
CPU SCHEDULING
SCHEDULING ALGORITHM
Shortest Remaining Job First (SRJF)
Mode:Preemptive / Burst Time
Queue Arrival Burst Completion Turn Around Waiting Response
Time Time Time Time (CT-AT) ((TAT-BT) Time
P1 0 8 20 20 12
P2 1 4 10 9 5
P3 2 2 4 2 0
P4 3 1 5 2 1
P5 4 3 13 9 6
P6 5 2 7 2 0
CPU SCHEDULING
SCHEDULING ALGORITHM
Round Robin Scheduling (RR)
Mode:Preemptive / Time Quantum: 5
Queue Arrival Burst Time Completion Turn Around Waiting
Time Time Time (CT-AT) ((TAT-BT)
P1 0 21
P2 0 3
P3 0 6
P4 0 2
CPU SCHEDULING
SCHEDULING ALGORITHM
Round Robin Scheduling (RR)
Mode:Preemptive / Arrival Time
Queue Arrival Burst Time Completion Turn Around Waiting
Time Time Time (CT-AT) ((TAT-BT)
P1 0 21
P2 0 3
P3 0 6
P4 0 2
CPU SCHEDULING
SCHEDULING ALGORITHM
Round Robin Scheduling (RR)
Mode:Preemptive / Time Quantum: 2