You are on page 1of 15

CPU Scheduling Algorithms

P.Naveen 10111D0030

Agenda
Scheduling Types of Short Term Scheduling FCFS SJF Scheduling Disadvantages of SJF scheduling

Scheduling
In computer science, a scheduling is the method by which threads, processes or data flows are given access to system

resources (e.g. processor time, communications bandwidth).


This is usually done to load balance a system effectively or achieve a target quality of service.

The need for a scheduling algorithm arises from the requirement for
most modern systems to perform multitasking(execute more than one process at a time) and multiplexing (transmit multiple flows simultaneously).

Types of Short term scheduling


Work centres loading Job sequencing

FCFS
Non Preemptive Treats ready queue as FIFO Simple, but typically long waiting time. Other Names: First-in First-out(FIFO) Run to completion Run until done

SJF Scheduling
Give CPU to the process with the shortest next burst Schedule the process with the shortest CPU Burst time Two schemes:
Non preemptive once CPU given to the process it cannot be preempted (stopped) until completes its CPU burst preemptive if a new process arrives with CPU burst length less than remaining time of current executing process, preempt. This scheme is know as the Shortest-Remaining-Time-First (SRTF)

SJF is optimal gives minimum average waiting time for a given set of processes

Disadvantages of SJF
Only optimal if all process are available simultaneously Usually run times are not known

Shortest Job First Scheduling


Example: Process P1 P2 P3 P4 Non preemptive SJF Arrival Time Burst Time 0 7 2 4 4 1 5 4

Average waiting time = (0 + 6 + 3 + 7)/4 = 4

P1 0 P1(7) P2(4) P3(1) P4(4) 2 4 5

P3 7 8

P2 12

P4 16 P1s wating time = 0 P2s wating time = 6

P3s wating time = 3


P4s wating time = 7

Shortest Job First Scheduling Contd


Example: Process P1 P2 P3 P4 Preemptive SJF Arrival Time Burst Time 0 7 2 4 4 1 5 4

Average waiting time = (9 + 1 + 0 +2)/4 = 3

P1
P1(7) 0 2 P1(5)

P2 P3
4 5

P2 7

P4
11

P1 16 P1s waiting time = 9 P2s waiting time = 1

P2(4) P2(2) P3(1) P4(4)

P3s waiting time = 0


P4s waiting time = 2

Shortest Job First Scheduling Contd

10

Optimal scheduling Preemptive SJF is superior to non preemptive SJF. However, there are no accurate estimations to know the length of the next CPU burst

11

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 in Unix but lowest in Java). Preemptive Non-preemptive

Round Robin Scheduling


12

Each process is given CPU time in turn, (i.e. time quantum: usually 10-100 milliseconds), and thus waits no longer than ( n 1 ) * time quantum time quantum = 20 Process Burst Time Wait Time P1 53 57 +24 = 81 P2 17 20 P3 68 37 + 40 + 17= 94 P4 24 57 + 40 = 97

P1 P2 P3 P4 P1 P3 P4 P1 P3 P3 0 20 37 57 77 97 117 121 134 154 162 P1(53) P2(17) 20 P3(68) P4(24)


37 57 57

P1(33) P3(48)
40

P 24 1(13)

40

17

P3(28) P3(8)

P4(4)
Average wait time = (81+20+94+97)/4 = 73

Round Robin Scheduling

13

Typically, higher average turnaround than SJF, but better response. Performance q large FCFS q small q must be large with respect to context switch, otherwise overhead is too high.

SJF preemptive vs Round Robin


Among all the scheduling process, SJF has the minimal waiting time.

Thank You

You might also like