8 - RR, Priority CPU Scheduling

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 12

Process Management:

Process/CPU Scheduling
Content
 Recap: Example of FCFS, SJF, SRTF
Process Scheduling Algorithms
Priority Scheduling
Non-Preemptive
Preemptive
Round-Robin
Multi-level Queue
Multi-level Feedback Queue
Round Robin (RR) Scheduling
Criteria: Time Quantum
 Mode: Preemptive
Sequence of processes in the ready queue
Each process gets a small unit of CPU time (time quantum q), usually 10-100
milliseconds. After this time has elapsed, the process is preempted and added to
the end of the ready queue.
If there are n processes in the ready queue and the time quantum is q, then each
process gets 1/n of the CPU time in chunks of at most q time units at once. No
process waits more than (n-1)q time units.
Timer interrupts every quantum to schedule next process
 Performance
◦ q large  FIFO (FCFS)
◦ q small  RR
RR Scheduling Cont..
Note that q must be large with respect to context switch, otherwise overhead is
too high

q should be large compared to context switch time


◦ q usually 10 milliseconds to 100 milliseconds,
◦ Context switch < 10 microseconds

Typically, higher average turnaround than SJF, but better response time
Time Quantum and Context Switch Time
Turnaround Time Varies With The Time Quantum

80% of CPU bursts should be shorter than q


Example of RR Scheduling

Process Arrival Time Burst Time CT TAT WT RT


P1 0 5
P2 1 4
P3 2 2
P4 4 1
TAT = CT- AT
WT = TAT- BT
RT = CPU first time- AT

Derive Number of context switches?


Priority Scheduling

Criteria: Priority
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

SJF is priority scheduling where priority is the inverse of predicted next CPU
burst time
Problem: Starvation (indefinite blocking)– low priority processes may never
execute
Solution: Aging – as time progresses increase the priority of the process/
gradually increasing the priority of processes that wait in the system for a long
time.
Example of Priority Scheduling (non-preemptive)

Process Priority Arrival Time Burst Time CT TAT WT RT


P1 10 0 5
P2 20 1 4
P3 30 2 2
P4 40 4 1
TAT = CT- AT
WT = TAT- BT
RT = CPU first time- AT

If two processes have same priority then go with arrival time.
Example of Priority Scheduling (preemptive)

Process Priority Arrival Time Burst Time CT TAT WT RT


P1 10 0 5
P2 20 1 4
P3 30 2 2
P4 40 4 1
TAT = CT- AT
WT = TAT- BT
RT = CPU first time- AT

If two processes have same priority then go with arrival time.
Mixed Burst time (CPU & I/O Both)

Process Priority Arrival Time CPU I/O CPU CT TAT WT


P1 2 0 1 5 3
P2 3 2 3 3 1
P3 1 3 2 3 1
P4 4 3 2 4 1
TAT = CT- AT
WT = TAT- BT
RT = CPU first time- AT
Ratio of CPU idleness & CPU Usage?
Upcoming topics

 MLQ, MLFQ Scheduling


Process Synchronization

You might also like