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

CPU Scheduling

The document discusses several CPU scheduling algorithms: 1) First-Come, First-Served (FCFS) scheduling simply processes tasks in the order that they arrive in the ready queue. It performs poorly if short tasks are placed behind long tasks. 2) Shortest Job First (SJF) scheduling selects the task with the shortest execution time to run next. It aims to minimize average waiting time but requires knowing future task lengths. 3) Priority scheduling assigns priority levels to tasks and the highest priority task runs next. It risks lower priority tasks starving if not combined with aging to increase their priority over time.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
113 views

CPU Scheduling

The document discusses several CPU scheduling algorithms: 1) First-Come, First-Served (FCFS) scheduling simply processes tasks in the order that they arrive in the ready queue. It performs poorly if short tasks are placed behind long tasks. 2) Shortest Job First (SJF) scheduling selects the task with the shortest execution time to run next. It aims to minimize average waiting time but requires knowing future task lengths. 3) Priority scheduling assigns priority levels to tasks and the highest priority task runs next. It risks lower priority tasks starving if not combined with aging to increase their priority over time.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 29

CPU Scheduling Algorithms

Scheduling Criteria

 CPU utilization – keep the CPU as busy as possible

 Turnaround time – amount of time to execute a particular


process

 Waiting time – amount of time a process has been waiting


in the ready queue

 Response time – amount of time it takes from when a


request was submitted until the first response is produced,
not output (for time-sharing environment)
Scheduling Algorithm Optimization Criteria

 Max CPU utilization


 Max throughput
 Min turnaround time
 Min waiting time
 Min response time
First- Come, First-Served (FCFS) Scheduling

Process Burst Time


P1 24
P2 3
P3 3
 Suppose that the processes arrive in the order: P1 , P2 , P3
The Gantt Chart for the schedule is:

P1 P2 P3
0 24 27 30

 Waiting time for P1 = 0; P2 = 24; P3 = 27


 Average waiting time: (0 + 24 + 27)/3 = 17
FCFS Scheduling

Suppose that the processes arrive in the order:


P2 , P3 , P1
 The Gantt chart for the schedule is:

P2 P3 P1
0 3 6 30

 Waiting time for P1 = 6; P2 = 0; P3 = 3


 Average waiting time: (6 + 0 + 3)/3 = 3
 Much better than previous case
 Not effective when short process behind long process
FCFS Scheduling
Shortest-Job-First (SJF) Scheduling

 Associate with each process the length of its next CPU burst
 Use these lengths to schedule the process with the shortest
time
 SJF is optimal – gives minimum average waiting time for a
given set of processes
 The difficulty is knowing the length of the next CPU request
 Could ask the user
Example of SJF

Process Arrival Time Burst Time


P1 0.0 6
P2 2.0 8
P3 4.0 7
P4 5.0 3

 SJF scheduling chart

P4 P1 P3 P2
0 3 9 16 24

 Average waiting time = (3 + 16 + 9 + 0) / 4 = 7


Example of Shortest-remaining-time-first

Process A Arrival Time Burst Time


P1 0 8
P2 1 4
P3 2 9
P4 3 5

 Preemptive SJF Gantt Chart

P1 P2 P4 P1 P3
0 1 5 10 17 26

 Waiting Time = [Total waiting time - No. of units process executed


- Arrival Time]
 Average waiting time = [(10-1-0)+(1-0-1)+(17-0-2)+(5-0-3)]/4 =
[9+0+15+2]/4 = 26/4 = 6.5
SRTF

Find Average Waiting Time


SRTF
SRTF

Find Average Turn Around Time


SRTF
Priority Scheduling

 A priority number (integer) is associated with each process

 The CPU is allocated to the process with the highest priority


(smallest integer  highest priority)

 SJF is priority scheduling where priority is the inverse of predicted


next CPU burst time

 Problem  Starvation – low priority processes may never execute

 Solution  Aging – as time progresses increase the priority of the


process
Example of Priority Scheduling

Process Burst Time Priority


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

 Priority scheduling Gantt Chart

 Average waiting time = 8.2 msec


PRIO

Find Average Waiting Time


PRIO
Round Robin (RR)

 Each process gets a small unit of CPU time (time


quantum q).

 After this time has elapsed, the process is preempted


and added to the end of the ready queue.
Round Robin (RR)
Example of RR with Time Quantum = 4

Process Burst Time


P1 24
P2 3
P3 3

 The Gantt chart is:

 Typically, higher average turnaround than SJF, but better response


 q should be large compared to context switch time
 q usually 10ms to 100ms, context switch < 10 usec
RR
RR
Time Quantum – 2ms
RR
RR
Earliest Deadline First Scheduling (EDF)

 Priorities are assigned according to deadlines:

 the earlier the deadline, the higher the priority;


the later the deadline, the lower the priority

Dynamic Priority Scheduling


FCFS Scheduling
FCFS Scheduling
FCFS Scheduling
THANKS

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy