M2S2-SUPPLEMENTARY1
M2S2-SUPPLEMENTARY1
Example 1:
• Consider the following set of processes that arrive at time 0, with the length of the CPU
burst given in milliseconds (ms).
• Illustrate the Gantt chart and compute for the average waiting time and average
turnaround time
Given:
Arrival Burst Waiting Turnaround
Process
Time time Time Time
P1 0 5 0-0 = 0 5-0 = 5
P2 0 3 5-0 = 5 8-0 = 8
P3 0 8 8-0 = 8 16-0 =16
P4 0 6 16-0 = 16 22-0 = 22
29/4 51/4
Average
7.25 ms 12.75 ms
Gantt Chart:
1
Formulas:
Example 2:
Arrival Burst Waiting Turnaround
Process
Time time Time Time
P1 0 5 0-0 = 0 5-0 = 5
P2 1 3 5-1 = 4 8-1 = 7
P3 2 8 8-2 =6 16-2 = 14
P4 3 6 16-3 = 13 22-3 = 19
23/4 45/4
Average
5.75 ms 11.25 ms
Gantt Chart:
• SJF algorithm associates with each process the length of the latter’s next CPU burst.
• When the CPU is available, it is assigned to the process that has the smallest next
CPU burst.
• If two processes have the same length next CPU burst, FCFS scheduling is used to
break the tie.
2
Example 1:
Gantt Chart:
Example 2:
Gantt Chart:
3
PRIORITY SCHEDULING (NP)
Example 1:
Consider the lowest priority value gets the highest priority. In this case, process with priority
value (1) is the highest priority.
Gantt Chart:
REFERENCES