Lecture 17
Lecture 17
• CPU Scheduling is a process of determining which process will own CPU for
execution while another process is on hold. The main task of CPU scheduling is to
make sure that whenever the CPU remains idle, the OS at least select one of the
processes available in the ready queue for execution. The selection process will
be carried out by the CPU scheduler. It selects one of the processes in memory
that are ready for execution.
Why do we need Scheduling?
•In Multiprogramming, if the long term scheduler picks more I/O bound
processes then most of the time, the CPU remains idol. The task of Operating
system is to optimize the utilization of resources.
•If most of the running processes change their state from running to waiting
then there may always be a possibility of deadlock in the system. Hence to
reduce this overhead, the OS needs to schedule the jobs to get the optimal
utilization of CPU and to avoid the possibility to deadlock.
Types of CPU Scheduling
Preemptive Scheduling
Preemptive scheduling is a CPU
scheduling technique where a running
process can be interrupted and moved
to the ready queue to allow another
process to execute. The OS decides
which process runs based on priority
or scheduling policies.
Non-Preemptive Scheduling
Non-preemptive scheduling is a CPU
scheduling method where a
process runs until it either completes or
voluntarily enters a waiting state (e.g., for
Types of CPU Scheduling
Examples of Non-Preemptive Scheduling Algorithms Examples of Preemptive Scheduling
1.First-Come, First-Served (FCFS) Algorithms
1. The first process to arrive gets executed first.
2. Simple but can cause the convoy effect (slow 1.Round Robin (RR)
processes delay fast ones). 1.Each process gets a fixed time
2.Shortest Job Next (SJN) / Shortest Job First (SJF)
(Non-Preemptive Version)
slice (quantum) before being
1. The process with the shortest execution time is preempted.
selected next. 2.Shortest Remaining Time First (SRTF)
2. Can cause starvation (longer processes may
wait indefinitely). 1.The process with the shortest
3.Priority Scheduling (Non-Preemptive Version) remaining execution time runs
1. The process with the highest priority runs first.
2. Risk of starvation for lower-priority processes.
next.
3.Priority Scheduling (Preemptive
Version)
1.A higher-priority process can
preempt a lower-priority one.
Important CPU scheduling Terminologies
Burst Time/Execution Time: It is a time required by the process to complete execution. It
is also called running time.
Arrival Time: when a process enters in a ready state
Finish Time: when process complete and exit from a system
Multiprogramming: A number of programs which can be present in memory at the same
time.
Jobs: It is a type of program without any kind of user interaction.
User: It is a kind of program having user interaction.
Turnaround Time (TAT) It is the time interval from the time of
submission of a process to the time of the completion of the process.
CPU Scheduling Criteria
•A CPU scheduling algorithm tries to maximize and minimize the following:
CPU Scheduling Criteria
•Maximize:
•CPU utilization: CPU utilization is the main task in which the operating system needs to make
sure that CPU remains as busy as possible. It can range from 0 to 100 percent. However, for the
RTOS, it can be range from 40 percent for low-level and 90 percent for the high-level system.
•Throughput: The number of processes that finish their execution per unit time is known
Throughput. So, when the CPU is busy executing the process, at that time, work is being done,
and the work completed per unit time is called Throughput.
•Minimize:
•Waiting time: Waiting time is an amount that specific process needs to wait in the ready queue.
•Response time: It is an amount to time in which the request was submitted until the first
response is produced.
•Turnaround Time:
•It is the calculation of the total time spent waiting to get into the memory, waiting in the queue
and, executing on the CPU. The period between the time of process submission to the
completion time is the turnaround time.
Types of CPU scheduling Algorithm
There are mainly six types of process scheduling algorithms
It's easy to understand and implement programmatically, using a Queue data structure, where
a new process enters through the tail of the queue, and the scheduler selects process from
the head of the queue.
A perfect real life example of FCFS scheduling is buying tickets at ticket counter.
First Come First Serve Scheduling
Calculating Average Waiting Time
TAT=CT−AT
WT=TAT−BT
Process Arrival Time Burst Time Completion Time Turn Around Time Waiting Time
P0 0 2
P1 1 6
P2 2 4
P3 3 9
P4 4 12
First Come First Serve Scheduling
• Consider the following set of processes that arrive at different times in a system. Using the First-Come, First-Served
(FCFS) scheduling algorithm, calculate:
1. Completion Time (CT)
2. Turnaround Time (TAT)
3. Waiting Time (WT)
4. Average Turnaround Time
5. Average Waiting Time
6. Draw the Gantt Chart