0% found this document useful (0 votes)
16 views15 pages

CPU Scheduling

Uploaded by

sketchyyb
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)
16 views15 pages

CPU Scheduling

Uploaded by

sketchyyb
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/ 15

CPU Scheduling

Algorithms
PRESENTED BY: BHAVNEET KAUR (ROLL NO. 25)
DEFINITION:

CPU scheduling is the process by which the operating system


decides which process from the ready queue should execute next
on the CPU.
OBJECTIVE:
(1) Maximize CPU Utilization:
The CPU must be kept busy as much as possible. Idle time should be minimized.
(2) Improve System Throughput:
The number of processes completed per unit of time should be maximized.
(3) Fair Process Allocation:
Ensure that each process gets its fair share of CPU time.
(4) Minimize Turnaround Time and Waiting Time:
Reduce delays and make system responses quicker.
Types of CPU Scheduling
Algorithms
Preemptive Scheduling:
In this type, the operating system can interrupt a running process and allocate CPU time
to another process. Preemption can occur before the current process finishes its execution.
Example: Round Robin, Priority scheduling etc.

Non-preemptive Scheduling:
Here, once a process starts executing on the CPU, it runs to completion without being
interrupted by other processes. The CPU is only reassigned when the running process is
terminated or completed.
Example: FCFS
First-Come, First-Served (FCFS)
Description:
Processes are executed in the order they arrive in the ready queue. This
is a non-preemptive scheduling algorithm.

Pros: Simple and easy to implement.


Cons: Can lead to high waiting time for short processes.
EXAMPLE :
Process Arrival Time Burst Time
P1 0 6
P2 1 8
P3 2 4

Gantt Chart:
P1 P2 P3
0 6 14 18

Average Waiting Time = (0+5+12​)/ 3 = 17/3 ​= 5.67 ms

Average Turnaround Time = (6+13+16)/ 3​= 35/3 ​= 11.67 ms


Shortest Job First (SJF)
Description:
SJF executes the process with the shortest burst time first. It can be
non-preemptive or preemptive (Shortest Remaining Time First, SRTF).

Pros: Minimizes average waiting time.


Cons: Can lead to starvation of longer processes.
EXAMPLE :
Process Arrival Time Burst Time
P1 0 6
P2 1 2
P3 2 8

Gantt Chart:
P1 P3 P2
0 6 10 18

Average Waiting Time = (0+9+4​)/3 = 13/3​= 4.33 ms

Average Turnaround Time = (6+17+8)/3 ​= 31/3 ​= 10.33 ms


Round Robin (RR)
Description:
Round Robin assigns each process a fixed time quantum (time slice).
When a process uses up its time quantum, it is moved to the end of the
ready queue, and the next process is executed.

Pros: Prevents starvation by giving each process equal time slices.


Cons: The choice of time quantum is crucial for performance.
EXAMPLE : Time Quantum = 4 ms
Process Arrival Time Burst Time
P1 0 6
P2 1 8
P3 2 4

Gantt Chart:
P1 P2 P3 P1 P2
0 4 8 12 16 20

Average Waiting Time = (8+9+6)​/3 = 23/3 ​≈ 7.67

Average Turnaround Time = (14+17+10)/3 ​= 41/3 ​≈ 13.67


Priority Scheduling
Description:
Each process is assigned a priority. The process with the highest
priority (usually the smallest number) is executed first. It can be either
preemptive or non-preemptive.

Pros: Prioritizes important tasks


Cons: Low-priority processes might never get executed.
EXAMPLE :
Process Arrival Time Burst Time Priority
P1 0 5 3
P2 1 3 1
P3 2 4 2

Gantt Chart:
P1 P2 P3 P1
0 1 4 7 10

Average Waiting Time = (5+0+1)/3 = 6/3​= 2

Average Turnaround Time = (10+3+5)/3 ​= 18/3 ​= 6


Multilevel Queue Scheduling
Description:
This algorithm maintains several ready queues, each assigned to a different
priority level. Processes are permanently assigned to one queue based on their
priority or characteristics
(e.g., interactive vs. CPU-bound).

Pros: Suitable for systems where processes can be classified into different
categories
Cons: Processes in lower-priority queues may experience starvation.
EXAMPLE :
Process Arrival Time Burst Time Priority
P1 0 6 High
P2 1 8 Low
P3 2 4 Low

• It can be simplified by Multilevel Queue Scheduling


with two queues:
Queue 1: High priority, uses First-Come, First-Served (FCFS).
Queue 2: Low priority, uses Round Robin (RR) with a time
quantum of 2 units.
• P1 has High priority, so it will be scheduled in Queue 1 (FCFS).
• P2 and P3 have Low priority, so they will be scheduled in Queue 2
(Round Robin).
THANKYOU

You might also like