Week 05 Lecture Chapter 5
Week 05 Lecture Chapter 5
Scheduling Algorithms
First-Come, First-Served Scheduling
Shortest-Job-First Scheduling
Priority Scheduling
Round-Robin Scheduling
Scheduling Algorithms
3. Priority Scheduling
P1 P2 P3
0 24 27 30
P2 P3 P1
0 3 6 30
P3 P2 P4 P1
0 1 5 9 16
Two schemes:
P1 P3 P2 P4
0 7 8 12 16
P1 P2 P3 P2 P4 P1
0 2 4 5 7 11 16
P2 P5 P1 P3 P4
0 1 6 16 18 19
Two schemes:
Nonpreemptive
Preemptive.
Round Robin (RR)
The round-robin (RR) scheduling algorithm is designed especially
for time-sharing system.
Each process gets a small unit of CPU time (time quantum q),
usually 10-100 milliseconds in length. 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:
If the time quantum is extremely large, the RR policy is the same
as the FCFS policy.
If the time quantum is extremely small (say, 1 millisecond), the
RR approach can result in a large number of context switches.
Round Robin (RR)
P1 P2 P3 P1 P1 P1 P1 P1
0 4 7 10 14 18 22 26 30
The processes are assumed to have arrived in the order P1, P2, P3, P4, P5, all at time 0.
a. Draw FIVE (5) Gantt charts that illustrate the execution of these processes using
the following scheduling algorithms: FCFS, SJF, non-preemptive priority (a
smaller number implies a higher priority) and RR (for quantum = 1 and =2).
b. What is the waiting time for each process for each of these scheduling algorithms?
c. Which of the algorithms results in the minimum average waiting time (over all
processes)?
Exercise (2)
Consider the following set of processes, with the length of the CPU-burst time given in
milliseconds:
Process Burst Time Priority
P1 9 2
P2 2 0
P3 3 2
P4 3 3
P5 7 1
The processes are assumed to have arrived in the order P1, P2, P3, P4, P5, all at time 0.
a. Draw four Gantt charts that illustrate the execution of these processes using the
following scheduling algorithms: FCFS, SJF, non-preemptive priority (a smaller number
implies a higher priority) and RR (quantum = 2).
b. What is the waiting time for each process for each of these scheduling algorithms?
c. Which of the algorithms results in the minimum average waiting time (over all
processes)?
Exercise (3)
Consider the following set of processes, with the length of the CPU-burst time given in
milliseconds:
Process Burst Time Arrival Time
P1 2 1
P2 4 2
P3 2 0
P4 5 4
P5 3 3
a. Draw THREE (3) Gantt charts that illustrate the execution of these processes using
the following scheduling algorithms: FCFS, and RR (for quantum = 1 and =2).
b. What is the waiting time for each process for each of these scheduling algorithms?
c. Which of the algorithms results in the minimum average waiting time (over all
processes)?