0% found this document useful (0 votes)
8 views14 pages

Lecture 17

The document discusses CPU scheduling, which is essential for managing process execution in operating systems. It outlines various scheduling algorithms, including First-Come, First-Served (FCFS), Shortest Job First (SJF), Round Robin, and Priority Scheduling, along with their characteristics and performance metrics. Additionally, it explains key terminologies and criteria for evaluating scheduling effectiveness, such as CPU utilization, waiting time, and turnaround time.

Uploaded by

Rfor Ptanhi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views14 pages

Lecture 17

The document discusses CPU scheduling, which is essential for managing process execution in operating systems. It outlines various scheduling algorithms, including First-Come, First-Served (FCFS), Shortest Job First (SJF), Round Robin, and Priority Scheduling, along with their characteristics and performance metrics. Additionally, it explains key terminologies and criteria for evaluating scheduling effectiveness, such as CPU utilization, waiting time, and turnaround time.

Uploaded by

Rfor Ptanhi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 14

Scheduling algorithms: FCFS,

SJF, Round Robin, Priority


Scheduling

• 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

1. First Come First Serve (FCFS)


2. Shortest-Job-First (SJF) Scheduling
3. Shortest Remaining Time
4. Priority Scheduling
5. Round Robin Scheduling
6. Multilevel Queue Scheduling
First Come First Serve Scheduling
•In the "First come first serve" scheduling algorithm, as the name suggests, the process which
arrives first, gets executed first, or we can say that the process which requests the CPU first, gets
the CPU allocated first.
 First Come First Serve is just like FIFO (First in First out) Queue data structure, where the data
element which is added to the queue first, is the one who leaves the queue first.
 This is used in Batch Systems.

 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

• For every scheduling algorithm, Average waiting time is a crucial parameter to


judge it's performance.
• AWT or Average waiting time is the average of the waiting times of the
processes in the queue, waiting for the scheduler to pick them for execution.
• Lower the Average Waiting Time, better the scheduling algorithm.
• Consider the processes P1, P2, P3, P4 given in the below table, arrives for
execution in the same order, with Arrival Time 0 and given Burst Time, let's
find the average waiting time using the FCFS scheduling algorithm.
First Come First Serve Scheduling

Completion Time (CT): The time at which the


process finishes execution.

CT= StartTime+ BurstTime

Turn Around Time (TAT): The total time a


process spends in the system.

TAT=CT−AT

Waiting Time (WT): The time a process spends


waiting before execution.

WT=TAT−BT

Q. Calculate CT, TAT and WT


First Come First Serve Scheduling
• Let's take an example of The FCFS scheduling algorithm. In the Following schedule,
there are 5 processes with process ID P0, P1, P2, P3 and P4. P0 arrives at time 0, P1 at
time 1, P2 at time 2, P3 arrives at time 3 and Process P4 arrives at time 4 in the ready
queue. The processes and their respective Arrival and Burst time are given in the
following table:

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

Process Arrival Time (AT) Burst Time (BT)


P1 2 ms 4 ms
P2 0 ms 8 ms
P3 1 ms 3 ms
P4 3 ms 6 ms

You might also like