Cpscheduling
Cpscheduling
CPU Scheduling
Long-term scheduler:
Bring process to Ready state
Short-term scheduler:
Dispatcher/ CPU scheduler
Bring process in Running state
Medium-term scheduler
Swapping out and Swapping in the process
from main memory to secondary memory.
What is a CPU Scheduling?
P1 P2 P3
0 24 27 30
Waiting Time for P = 0; P = 24 P = 27
1 2 ; 3
Average Waiting Time: (0+24+27)/3=17 milliseconds.
First Come First Served Scheduling contd..
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 milliseconds
Much better than previous case
0 3 9 16 24
=1
n+1 = tn
Only the actual last CPU burst counts.
P1 P2 P4 P1 P3
0
Preemptive SJF 1
Average 10
5waiting time: 17 26
[(10-1)+(1-1)+(17-2)+(5-3)]/4=26/4=6.5ms
Non-preemptive average waiting time: [0+(8-1)+(17-
2)+(12-3)]/4 =31/4=7.75ms
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)
Preemptive
Non-preemptive
Equal priority processes are scheduled in FCFS order.
SJF algorithm is a priority scheduling where priority is the
predicted next CPU burst time
Problem Starvation – low priority processes may never
execute
Solution Aging – as time progresses increase the priority of
the process
Priority Scheduling contd..
Process Burst Time Priority
P1 10 3
P2 1 1
P3 2 4
P4 1 5
P5 5 2
Gantt chart:
P2 P5 P1 P3 P4
0 1 6 16 18 19
0 4 7 10 14 18 22 26 30
0 2 4 6 7 10 12 14 15 20
Multilevel Feedback Queue Scheduling
A process can move between the various queues: On the
basis of its CPU burst.
If process uses too much CPU time, it will be moved to a lower-
priority queue.
This scheme leaves I/O bound and interactive processes in the
higher-priority queue.
Process waiting too long in a lower-priority may be moved to
higher-priority queue. Aging can implemented in this way.
Multithreading Models:
One to one model
Many to one model
Many to many model
Hybrid model
Thread Scheduling
Scheduling of user level threads
P2 100s 35s