0% found this document useful (0 votes)
9 views11 pages

Scheduling

Uploaded by

Jack Ripper
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)
9 views11 pages

Scheduling

Uploaded by

Jack Ripper
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/ 11

Scheduling Algorithms

n First Come First Serve (FCFS)


n Shortest Job First
n Round Robin
n Priority Scheduling

1
First Come First Serve (FCFS)
n Process that requests the CPU FIRST is allocated the CPU
FIRST.
n Also called FIFO
n Implementation
n FIFO queue
n A new process enters the tail of the queue
n The scheduler selects the process at the head of the queue.

2
FCFS Example
Process Duration Order Arrival Time
P1 24 1 0
P2 3 2 0
P3 4 3 0
P1 (24) P2 (3) P3 (4)
0 24 27

P1 waiting time: 0
The average waiting time:
P2 waiting time: 24
P3 waiting time: 27 (0+24+27)/3 = 17

3
Round-robin
n One of the oldest, simplest, most commonly used
scheduling algorithm
n Select process/thread from ready queue in a
round-robin fashion (take turns)

Problems:
• Does not consider priority
• Context switch overhead

Preemption after
quantum
expiration
4
Round-robin: Example
Process Duration Order Arrival Time
P1 3 1 0
P2 4 2 0
P3 3 3 0
Suppose time quantum is: 1 unit, P1, P2 & P3 never block
P1 P2 P3 P1 P2 P3 P1 P2 P3 P2

0 10
P1 waiting time: 4 The average waiting time (AWT):
P2 waiting time: 6
P3 waiting time: 6 (4+6+6)/3 = 5.33

5
Choosing the Time Quantum
n Time slice too large
n FIFO behavior
n Poor initial waiting time
n Time slice too small
n Too many context switches (overheads)
n Inefficient CPU utilization
n Heuristic:
n 70-80% of jobs block within time-slice
n Typical time-slice
n 10-100 ms (depends on job priority) 6
Shortest Job First (SJF)
n Schedule the job with the shortest
computation time first
n Scheduling in Batch Systems
n Optimal if all jobs are available
simultaneously: Gives the best possible AWT
(average waiting time)

7
SJF
Process Duration Order Arrival Time
P1 6 1 0
P2 8 2 0
P3 7 3 0
P4 3 4 0
P4 (3) P1 (6) P3 (7) P2 (8)

0 3 9 16 24
P4 waiting time: 0
The total time is: 24
P1 waiting time: 3
P3 waiting time: 9 The average waiting time (AWT):
P2 waiting time: 16 (0+3+9+16)/4 = 7
8
Copyright ©: Nahrstedt, Angrave, Abdelzaher

Comparing to FCFS
Process Duration Order Arrival Time
P1 6 1 0
P2 8 2 0
P3 7 3 0
P4 3 4 0

9
Copyright ©: Nahrstedt, Angrave, Abdelzaher

Comparing to FCFS
Process Duration Order Arrival Time
P1 6 1 0
P2 8 2 0
P3 7 3 0
P4 3 4 0
P1 (6) P2 (8) P3 (7) P4 (3)
14
0 6 The total time is the same. 21 24
P1 waiting time: 0
The average waiting time (AWT):
P2 waiting time: 6
P3 waiting time: 14 (0+6+14+21)/4 = 10.25
P4 waiting time: 21 (comparing to 7)
10
Priority-based Scheduling
Process Burst Time Priority
P1 10 3
P2 1 1
P3 2 4
P4 1 5
P5 5 2
P2 P5 P1 P3 P3 P4

0
1 6 16 18 19
P1 waiting time: 6
P2 waiting time: 0 The average waiting time (AWT):
P3 waiting time: 16 (6+0+16+18+1)/ 5=8.2
P4 waiting time: 18
P5 waiting time : 1 11
11

You might also like