0% found this document useful (0 votes)
2 views

CPU Scheduling Algorithms

CPU scheduling is a critical function of operating systems that determines the order of process execution on the CPU to optimize performance and resource utilization. Various algorithms such as First Come First Serve (FCFS), Shortest Job Next (SJN), Priority Based Scheduling, Round Robin, and Multiple-Level Queues are used to manage CPU time allocation effectively. Each algorithm has its own advantages and disadvantages, impacting metrics like turnaround time, waiting time, and overall system responsiveness.

Uploaded by

asokkrisha2275
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

CPU Scheduling Algorithms

CPU scheduling is a critical function of operating systems that determines the order of process execution on the CPU to optimize performance and resource utilization. Various algorithms such as First Come First Serve (FCFS), Shortest Job Next (SJN), Priority Based Scheduling, Round Robin, and Multiple-Level Queues are used to manage CPU time allocation effectively. Each algorithm has its own advantages and disadvantages, impacting metrics like turnaround time, waiting time, and overall system responsiveness.

Uploaded by

asokkrisha2275
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 19

CPU Scheduling

Algorithms
CPU scheduling

• CPU scheduling is a core function of operating systems that manages the


order in which processes and threads are executed on the CPU

• Ensures efficient utilization of the CPU’s processing power, enhancing


system performance and responsiveness
Why CPU Scheduling?

• In multitasking environments, multiple processes and threads compete for


the CPU’s attention

• Without scheduling, processes might monopolize the CPU, leading to poor


resource utilization and sluggish system performance

• Scheduling optimizes the allocation of CPU time among these tasks


Objectives of Process Scheduling Algorithm
1. Maximum CPU utilization

2. Keep the CPU as busy as possible

3. Allocation of CPU should be fair

4. Throughput should be Maximum - i.e. Number of processes that complete their execution per

time unit should be maximized

5. Minimum turnaround time - i.e. time taken by a process to finish execution should be the least.

Turn Around Time = Completion Time – Arrival TimeThere should be a minimum

waiting time and the process should not starve in the ready queue.

7. Minimum response time - time when a process produces the first response should be as little as
CPU Scheduling Criteria
Non- Pre-emptive Scheduling
First Come First Serve (FCFS)

• Jobs are executed on first come, first serve basis

• Non-preemptive scheduling algorithm

• Easy to understand and implement

• Its implementation is based on FIFO queue

• Poor in performance as average wait time is high


Process Id Arrival time Burst time

P1 3 4
P2 5 3
P3 0 2
P4 5 1
P5 4 3

If the CPU scheduling policy is FCFS, calculate the average


waiting time and average turn around time.
Turn Around time = Exit time – Arrival time
Waiting time = Turn Around time – Burst time
Process Id Exit time Turn Around time Waiting time

P1 7 7–3=4 4–4=0
P2 13 13 – 5 = 8 8–3=5
P3 2 2–0=2 2–2=0
P4 14 14 – 5 = 9 9–1=8
P5 10 10 – 4 = 6 6–3=3
Average Turn Around time = (4 + 8 + 2 + 9 + 6) / 5 = 29 / 5 = 5.8 unit
Average waiting time = (0 + 5 + 0 + 8 + 3) / 5 = 16 / 5 = 3.2 unit
Shortest Job Next (SJN)

• Also known as shortest job first, or SJF

• This is a non-preemptive, pre-emptive scheduling algorithm.

• Best approach to minimize waiting time.

• Easy to implement in Batch systems where required CPU time is known in


advance.

• Impossible to implement in interactive systems where required CPU time is not


known.

• The processer should know in advance how much time process will take.
Priority Based Scheduling

• One of the most common scheduling algorithms in batch systems.

• Each process is assigned a priority

• Process with highest priority is to be executed first and so on

• Processes with same priority are executed on first come first served basis

• Priority can be decided based on memory requirements, time requirements


or any other resource requirement
• Process Arrival Time Execution Time Priority Service Time
• P0 0 5 1 0
• P1 1 3 2 11
• P2 2 8 1 14
• P3 3 6 3 5
Waiting time of each process is as follows −

Process Waiting Time


P0 0-0=0
P1 11 - 1 = 10
P2 14 - 2 = 12
P3 5-3=2
Average Wait Time: (0 + 10 + 12 + 2)/4 = 24 / 4 = 6
Round Robin Scheduling

• Round Robin is the preemptive process scheduling algorithm.

• Each process is provided a fix time to execute, it is called a quantum.

• Once a process is executed for a given time period, it is preempted


and other process executes for a given time period.

• Context switching is used to save states of preempted processes.


Wait time of each process is as follows −

Process Wait Time : Service Time - Arrival Time


P0 (0 - 0) + (12 - 3) = 9
P1 (3 - 1) = 2
P2 (6 - 2) + (14 - 9) + (20 - 17) = 12
P3 (9 - 3) + (17 - 12) = 11
Average Wait Time: (9+2+12+11) / 4 = 8.5
Multiple-Level Queues Scheduling
• Multiple-level queues are not an independent scheduling algorithm. They
make use of other existing algorithms to group and schedule jobs with
common characteristics.

• Multiple queues are maintained for processes with common characteristics.


• Each queue can have its own scheduling algorithms.
• Priorities are assigned to each queue.
• For example, CPU-bound jobs can be scheduled in one queue and all I/O-
bound jobs in another queue. The Process Scheduler then alternately selects
jobs from each queue and assigns them to the CPU based on the algorithm
assigned to the queue.

You might also like