Module 4 Scheduling Algorithm
Module 4 Scheduling Algorithm
Prepared by:
MAC JOHN T. POBLETE
Faculty, Information Technology Department
Cavite State University Naic
Email: [email protected]
ITEC55 Platform Technologies Module 4 Scheduling Algorithm
Instructions:
1. Read carefully all instruction for each task before working on the requirements.
2. All questions related to requirements shall be coursed through email only. Replies will be sent
during office hours.
Pretest:
Assume you have the following jobs to execute with one processor, with the jobs arriving in the order listed
here:
a. Suppose a system uses FCFS scheduling. Create a Gantt chart illustrating the execution of
these processes?
b. What is the turnaround time for process p3?
c. What is the average wait time for the processes?
LET US LEARN!
What is Preemptive Scheduling?
Preemptive Scheduling is a scheduling method where the tasks are mostly assigned with their priorities.
Sometimes it is important to run a task with a higher priority before another lower priority task, even if the lower priority
task is still running.
At that time, the lower priority task holds for some time and resumes when the higher priority task finishes its
execution.
In this process, the CPU is allocated to the processes In this process, CPU is allocated to the process until it
for a specific time period. terminates or switches to the waiting state.
Preemptive algorithm has the overhead of switching Non-preemptive Scheduling has no such overhead of
the process from the ready state to the running state switching the process from running into the ready state.
and vice-versa.
FCFS Example
Consider the set of 5 processes whose arrival time and burst time are given below-
Process Id Arrival time Burst time
P1 3 4
P2 5 3
P3 0 2
P4 5 1
P5 4 3
If the CPU scheduling policy is FCFS, calculate the average waiting time and average turnaround time,
throughput.
Gantt Chart
ITEC55 Platform Technologies Module 4 Scheduling Algorithm
Completion Turnaround
Process ID Arrival time Burst time Waiting Time
Time Time
P1 3 4 7 4 0
P2 5 3 13 8 5
P3 0 2 2 2 0
P4 5 1 14 9 8
P5 4 3 10 6 3
Non-Preemptive SJF
In non-preemptive scheduling, once the CPU cycle is allocated to process, the process holds it till it reaches
a waiting state or terminated.
Consider the following five processes each having its own unique burst time and arrival time.
Process ID Burst time Arrival time
P1 6 2
P2 2 5
ITEC55 Platform Technologies Module 4 Scheduling Algorithm
P3 8 1
P4 3 0
P5 4 4
Step 0) At time=0, P4 arrives and starts execution.
Step 1) At time= 1, Process P3 arrives. But, P4 still needs 2 execution units to complete. It will continue execution.
Step 2) At time =2, process P1 arrives and is added to the waiting queue. P4 will continue execution.
Step 3) At time = 3, process P4 will finish its execution. The burst time of P3 and P1 is compared. Process P1 is
executed because its burst time is less compared to P3.
Step 4) At time = 4, process P5 arrives and is added to the waiting queue. P1 will continue execution.
Step 5) At time = 5, process P2 arrives and is added to the waiting queue. P1 will continue execution.
Step 6) At time = 9, process P1 will finish its execution. The burst time of P3, P5, and P2 is compared. Process P2 is
executed because its burst time is the lowest.
ITEC55 Platform Technologies Module 4 Scheduling Algorithm
Step 8) At time = 11, process P2 will finish its execution. The burst time of P3 and P5 is compared. Process P5 is
executed because its burst time is lower.
Step 11) Complete the table in order to solve for AWT, ATA, throughput and CPU utilization.
Completion Turnaround
Process ID Arrival time Burst time Waiting Time
Time Time
P1 2 6 9 7 1
P2 5 2 11 6 4
P3 1 8 23 22 14
P4 0 3 3 3 0
P5 4 4 15 11 7
Throughput: 4.6
CPU Utilization: 100%
Step 1) At time= 1, Process P3 arrives. But, P4 has a shorter burst time. It will continue execution.
Step 2) At time = 2, process P1 arrives with burst time = 6. The burst time is more than that of P4. Hence, P4 will
continue execution.
Step 3) At time = 3, process P4 will finish its execution. The burst time of P3 and P1 is compared. Process P1 is
executed because its burst time is lower.
ITEC55 Platform Technologies Module 4 Scheduling Algorithm
Step 4) At time = 4, process P5 will arrive. The burst time of P3, P5, and P1 is compared. Process P5 is executed
because its burst time is lowest. Process P1 is preempted.
Process Queue Burst time Arrival time
P1 5 out of 6 is remaining 2
P2 2 5
P3 8 1
P4 3 0
P5 4 4
Step 5) At time = 5, process P2 will arrive. The burst time of P1, P2, P3, and P5 is compared. Process P2 is executed
because its burst time is least. Process P5 is preempted.
Process Queue Burst time Arrival time
P1 5 out of 6 is remaining 2
P2 2 5
P3 8 1
P4 3 0
P5 3 out of 4 is remaining 4
Step 7) At time =7, P2 finishes its execution. The burst time of P1, P3, and P5 is compared. Process P5 is executed
because its burst time is lesser.
Process Queue Burst time Arrival time
P1 5 out of 6 is remaining 2
P2 2 5
P3 8 1
P4 3 0
P5 3 out of 4 is remaining 4
ITEC55 Platform Technologies Module 4 Scheduling Algorithm
Step 8) At time =10, P5 will finish its execution. The burst time of P1 and P3 is compared. Process P1 is executed
because its burst time is less.
Step 9) At time =15, P1 finishes its execution. P3 is the only process left. It will start execution.
Step 11) Complete the table in order to solve for AWT, ATA, throughput and CPU utilization.
Completion Turnaround
Process ID Arrival time Burst time Waiting Time
Time Time
P1 2 6 15 13 7
P2 5 2 7 2 0
P3 1 8 23 22 14
P4 0 3 3 3 0
P5 4 4 10 6 2
GANTT chart
The P1 will be executed for 4 units first.
Ready Queue
Meanwhile the execution of P1, four more processes P2, P3, P4 and P5 arrives in the ready queue. P1 has
not completed yet, it needs another 1 unit of time hence it will also be added back to the ready queue.
P2 P3 P4 P5 P1
6 3 1 5 1
ITEC55 Platform Technologies Module 4 Scheduling Algorithm
GANTT chart
After P1, P2 will be executed for 4 units of time which is shown in the Gantt chart.
Ready Queue
During the execution of P2, one more process P6 is arrived in the ready queue. Since P2 has not completed
yet hence, P2 will also be added back to the ready queue with the remaining burst time 2 units.
P3 P4 P5 P1 P6 P2
3 1 5 1 4 2
GANTT chart
After P1 and P2, P3 will get executed for 3 units of time since its CPU burst time is only 3 seconds.
Ready Queue
Since P3 has been completed, hence it will be terminated and not be added to the ready queue. The next
process will be executed is P4.
P4 P5 P1 P6 P2
1 5 1 4 2
GANTT chart
After, P1, P2 and P3, P4 will get executed. Its burst time is only 1 unit which is lesser then the time quantum
hence it will be completed.
ITEC55 Platform Technologies Module 4 Scheduling Algorithm
Ready Queue
The next process in the ready queue is P5 with 5 units of burst time. Since P4 is completed hence it will not
be added back to the queue.
P5 P1 P6 P2
5 1 4 2
GANTT chart
P5 will be executed for the whole time slice because it requires 5 units of burst time which is higher than the
time slice.
Ready Queue
P5 has not been completed yet; it will be added back to the queue with the remaining burst time of 1 unit.
P1 P6 P2 P5
1 4 2 1
GANTT Chart
The process P1 will be given the next turn to complete its execution. Since it only requires 1 unit of burst time
hence it will be completed.
Ready Queue
P1 is completed and will not be added back to the ready queue. The next process P6 requires only 4 units of
burst time and it will be executed next.
P6 P2 P5
4 2 1
ITEC55 Platform Technologies Module 4 Scheduling Algorithm
GANTT chart
P6 will be executed for 4 units of time till completion.
Ready Queue
Since P6 is completed, hence it will not be added again to the queue. There are only two processes present
in the ready queue. The Next process P2 requires only 2 units of time.
P2 P5
2 1
GANTT Chart
P2 will get executed again, since it only requires only 2 units of time hence this will be completed.
Ready Queue
Now, the only available process in the queue is P5 which requires 1 unit of burst time. Since the time slice is
of 4 units hence it will be completed in the next burst.
P5
GANTT chart
P5 will get executed till completion.
ITEC55 Platform Technologies Module 4 Scheduling Algorithm
The completion time, Turnaround time and waiting time will be calculated as shown in the table below.
Process ID Arrival Time Burst Time Completion Turn Around Waiting Time
Time Time
P1 0 5 17 17 12
P2 1 6 23 22 16
P3 2 3 11 9 6
P4 3 1 12 9 8
P5 4 5 24 20 15
P6 6 4 21 15 11
Average 15.33 11.33
Throughput: 4
CPU Utilization: 100%
Post-Test
Solve for average waiting time, average turnaround time, throughput and CPU Utilization using the table
below. Use FCFS, SJF, SRTF and Round Robin (time slice=1). Show your solution.
Process Id Arrival time Burst time
P1 3 4
P2 5 3
P3 0 2
P4 5 1
P5 4 3