Published by: Zaya
Published date: 22 Jun 2021
Different time with respect to a process
A Process Scheduler schedules different processes to be assigned to the CPU based on particular scheduling algorithms. The rule or set of rules that are followed to schedule the process is known as the process scheduling algorithm. The algorithms are either non-preemptive or preemptive.
Advantages
Disadvantages
Example 1: Consider the following set of processes having their arrival time and CPU-burst time. Find the average waiting time and turnaround time using FCFS.
Process | Arrival Time (ms) | Burst Time (ms) |
P1 | 0 | 4 |
P2 | 1 | 3 |
P3 | 2 | 1 |
P4 | 3 | 2 |
P5 | 4 | 5 |
Solution:
Preparing Gantt chart using FCFS we get,
We know,
TAT (Turnaround Time) = CT (Completion Time) – AT (Arrival Time) and
WT (Waiting Time) = TAT (Turnaround Time) – BT (Burst Time)
Now finding TAT and WT,
Process | AT | BT | CT | TAT | WT |
P1 | 0 | 4 | 4 | 4 | 0 |
P2 | 1 | 3 | 7 | 6 | 3 |
P3 | 2 | 1 | 8 | 6 | 5 |
P4 | 3 | 2 | 10 | 7 | 5 |
P5 | 4 | 5 | 15 | 11 | 6 |
∑TAT= 34 | ∑WT= 18 |
Example 2: Consider the given processes with arrival and burst time given below. Schedule the given processes using FCFS and find average waiting time and average turn-around time.
PROCESSES | ARRIVAL TIME | BURST TIME |
A | 0 | 3 |
B | 2 | 6 |
C | 4 | 4 |
D | 6 | 5 |
E | 8 | 2 |
F | 3 | 4 |
SOLUTION:
Applying FCFS Gantt chart for the given processes becomes:
Now, from the Gantt chart,
Process | Arrival time (AT) |
Burst time (BT) |
Completion time (CT) |
Turnaround time TAT = CT – AT |
Waiting time WT=TAT-BT |
A | 0 | 3 | 3 | 3 | 0 |
B | 2 | 6 | 9 | 7 | 1 |
C | 4 | 4 | 17 | 13 | 9 |
D | 6 | 5 | 22 | 16 | 11 |
E | 8 | 2 | 24 | 16 | 14 |
F | 3 | 4 | 13 | 10 | 6 |
∑ TAT=65 | ∑ WT=41 |
Average turn-around time = ∑(TAT) / n = 65/6 = 10.83
Average waiting time = ∑(WT) / n =41/6 = 6.83
Example 3: Consider the processes P1, P2, P3, P4 given in the below table, arrives for execution in the same order, with Arrival Time 0, and given Burst Time, find the average waiting time using the FCFS scheduling algorithm.
Process | Burst Time (ms) |
P1 | 21 |
P2 | 3 |
P3 | 6 |
P4 | 2 |
Solution:
Now from the Gantt chart,
Process | Arrival Time (ms) |
Burst Time |
Completion Time |
Turnaround Time TAT=CT-AT |
Waiting Time WT = TAT - BT |
P1 | 0 | 21 | 21 | 21 | 0 |
P2 | 0 | 3 | 24 | 24 | 21 |
P3 | 0 | 6 | 30 | 30 | 24 |
P4 | 0 | 2 | 32 | 32 | 30 |
Average WT = (0+21+24+30)/4 = 18.75
Advantages:
Disadvantages:
Example 1: Consider the given processes with arrival and burst time given below. Schedule the given processes using SJF and find average waiting time (AWT) and average turnaround time(ATAT).
PROCESSES | ARRIVAL TIME |
BURST TIME |
A | 0 | 7 |
B | 2 | 5 |
C | 3 | 1 |
D | 4 | 2 |
E | 5 | 3 |
Solution:
According to the given question, the Gantt chart for SJF given processes becomes:
Now,
Calculating of TAT and WT using: TAT= CT – AT and WT = TAT - BT
Process | Arrival time | Burst time | Completion time |
Turn-around time |
Waiting time |
A | 0 | 7 | 7 | 7 | 0 |
B | 2 | 5 | 18 | 16 | 11 |
C | 3 | 1 | 8 | 5 | 4 |
D | 4 | 2 | 10 | 6 | 4 |
E | 5 | 3 | 13 | 8 | 5 |
∑TAT=42 | ∑WT=24 |
Average turn-around time = ∑(TAT) / n = 42/5 = 10.83
Average waiting time = ∑(WT) / n =24/5 = 4.8
Example 2: Five processes P1, P2, P3, P4, and P5 having burst time 5,3,4,3,1 arrives at CPU. Find the Average TAT and Average WT using the Shortest job first scheduling algorithm.
PROCESSES | BURST TIME (ms) |
P1 | 5 |
P2 | 3 |
P3 | 4 |
P4 | 3 |
P5 | 1 |
Solution
Since there is no arrival time so it is assumed all the processes arrive initially. i.e. AT=0
The Gantt chart for the above processes becomes:
Now, using the Gantt chart above and formula,
TAT = (CT-AT) and WT = (TAT-BT)
Process | Arrival time | Burst time | CT | TAT | WT |
P1 | 0 | 5 | 16 | 16 | 11 |
P2 | 0 | 3 | 7 | 7 | 4 |
P3 | 0 | 4 | 11 | 11 | 7 |
P4 | 0 | 3 | 4 | 4 | 1 |
P5 | 0 | 1 | 1 | 1 | 0 |
∑TAT=39 | ∑WT=23 |
Average turn-around time = ∑(TAT) / n = 39/5 = 7.8 ms
Average waiting time = ∑(WT) / n =23/5 = 4.6 ms
Example 3: Consider the given processes with arrival and burst time given below. Schedule the given processes using SJF and find waiting time and turn-around time.
PROCESSES | ARRIVAL TIME | BURST TIME |
A | 1 | 7 |
B | 2 | 5 |
C | 3 | 1 |
D | 4 | 2 |
E | 5 | 8 |
Solution
The Gantt chart for the above processes becomes:
Here no process arrives at time= 0, so the CPU stays in an idle position.
Now, using the Gantt chart above and formula,
TAT = (CT-AT) and WT = (TAT-BT)
Process | Arrival time | Burst time | CT | TAT | WT |
A | 1 | 7 | 8 | 7 | 0 |
B | 2 | 5 | 16 | 14 | 9 |
C | 3 | 1 | 9 | 6 | 5 |
D | 4 | 2 | 11 | 7 | 5 |
E | 5 | 8 | 24 | 19 | 11 |
Here Throughput = (5/24) and CPU Utilization = (23/24) of time. since CPU stay in idle for 1 unit of time.
Advantage:
Disadvantage:
Example 1: Consider the following processes with arrival time and burst time. Schedule them using SRT.
PROCESSES | ARRIVAL TIME(AT) | BRUST TIME (BT) |
A | 0 | 7 |
B | 1 | 5 |
C | 2 | 3 |
D | 3 | 1 |
E | 4 | 2 |
F | 5 | 1 |
Solution:
Gantt chart for the above processes becomes:
Process | Arrival time | Burst time | CT | TAT | WT |
A | 0 | 3 | 19 | 19 | 12 |
B | 2 | 6 | 13 | 12 | 7 |
C | 4 | 5 | 6 | 4 | 1 |
D | 6 | 4 | 4 | 1 | 0 |
E | 8 | 2 | 9 | 5 | 3 |
F | 5 | 1 | 7 | 2 | 1 |
∑TAT=43 | ∑WT=24 |
Average turn-around time = ∑(TAT) / n = 43/6 = 7.16 units
Average waiting time = ∑(WT) / n =24/6 = 4 units
Advantages of Priority Scheduling:
Disadvantages:
Priority scheduling is of both types: preemptive and non-preemptive.
a. Non-Preemptive Priority Scheduling
Example 1: There are 7 processes P1, P2, P3, P4, P5, P6, and P7. Their priorities, Arrival Time and burst time are given at the table. Find waiting time and response time using non-preemptive priority scheduling. Also, find the average WT.
Process | Priority | Arrival Time | Burst Time |
P1 | 2 | 0 | 3 |
P2 | 6 | 2 | 5 |
P3 | 3 | 1 | 4 |
P4 | 5 | 4 | 2 |
P5 | 7 | 6 | 9 |
P6 | 4 | 5 | 4 |
P7 | 10 | 7 | 10 |
Solution:
Gantt chart for the process is:
From the GANTT Chart prepared, we can determine the completion time of every process. The turnaround time, waiting time, and response time will be determined.
Turn Around Time = Completion Time - Arrival Time
Waiting Time = Turn Around Time - Burst Time
Response time = Time at which process get a first response – Arrival Time
Process | Priority | Arrival Time |
Burst Time |
Completion Time |
Turnaround Time |
Waiting Time |
Response Time |
P1 | 2 | 0 | 3 | 3 | 3 | 0 | 0 |
P2 | 6 | 2 | 5 | 18 | 16 | 11 | 13 |
P3 | 3 | 1 | 4 | 7 | 6 | 2 | 3 |
P4 | 5 | 4 | 2 | 13 | 9 | 7 | 11 |
P5 | 7 | 6 | 9 | 27 | 21 | 12 | 18 |
P6 | 4 | 5 | 4 | 11 | 6 | 2 | 7 |
P7 | 10 | 7 | 10 | 37 | 30 | 18 | 27 |
Average Waiting Time = (0+11+2+7+12+2+18)/7 = 52/7 units
Example 2: Consider the given processes below. Schedule the algorithm using non-preemptive priority, schedule the given processes. Assume 12 is the highest priority and 2 is the lowest priority.
Process | AT | BT (ms) | PRIORITY |
A | 0 | 4 | 2(lowest) |
B | 1 | 2 | 4 |
C | 2 | 3 | 6 |
D | 3 | 5 | 10 |
E | 4 | 1 | 3 |
F | 5 | 4 | 12(highest) |
G | 6 | 6 | 9 |
Solution:
b. Preemptive Priority Scheduling
In Preemptive Priority Scheduling, at the time of arrival of a process in the ready queue, its priority is compared with the priority of the other processes present in the ready queue as well as with the one which is being executed by the CPU at that point of time. The One with the highest priority among all the available processes will be given the CPU next.
Example 1: Consider the given processes below. Schedule the algorithm using the preemptive priority algorithm and hence find AWT and ATAT. Assume 12 is the highest priority and 2 as the lowest priority.
Process | AT | BT (ms) | PRIORITY |
A | 0 | 4 | 2(lowest) |
B | 1 | 2 | 4 |
C | 2 | 3 | 6 |
D | 3 | 5 | 10 |
E | 4 | 1 | 3 |
F | 5 | 4 | 12(highest) |
G | 6 | 6 | 9 |
Solution:
The Gantt chart for the given processes becomes: -
Now,
Process | AT | BT | PRIORITY | CT | TAT | WT |
A | 0 | 4 | 2 | 25 | 25 | 21 |
B | 1 | 2 | 4 | 21 | 20 | 18 |
C | 2 | 3 | 6 | 20 | 18 | 15 |
D | 3 | 5 | 10 | 12 | 9 | 4 |
E | 4 | 1 | 3 | 22 | 18 | 17 |
F | 5 | 4 | 12 | 9 | 4 | 0 |
G | 6 | 6 | 9 | 18 | 12 | 6 |
∑TAT=106 | ∑WT=81 |
Average turn-around time= (∑TAT=106)/7 = 15.14 ms
Average waiting time will be = (∑WT=81)/7 =11.57 ms
5. Round Robin Scheduling
Advantages:
Disadvantages:
Example 1: Consider the following processes with AT and BT given. Find waiting time and turnaround time using round robin with time quantum = 4.
PROCESSES | ARRIVAL TIME(AT) | BURST TIME (BT) |
A | 0 | 3 |
B | 2 | 6 |
C | 4 | 4 |
D | 6 | 5 |
E | 8 | 2 |
Solution:
Ready Queue: ABCDBED
Gantt chart:
Now,
Process | Arrival time | Burst time | CT | TAT | WT |
A | 0 | 3 | 3 | 3 | 0 |
B | 2 | 6 | 17 | 15 | 9 |
C | 4 | 5 | 11 | 7 | 2 |
D | 6 | 4 | 20 | 14 | 10 |
E | 8 | 2 | 19 | 11 | 9 |
vi. HRRN (Highest Response Ratio Next)
Advantages-
Disadvantages-
Example: Consider the following processes with AT and BT given. Find waiting time and turnaround time using HRRN.
PROCESSES | ARRIVAL TIME(AT) | BURST TIME (BT) |
A | 0 | 3 |
B | 2 | 6 |
C | 4 | 4 |
D | 6 | 5 |
E | 8 | 2 |
Solution:
Since (RR)E is larger than others hence E runs.
Now from the Gantt chart:
Process | Arrival time (AT) |
Burst time (BT) |
Completion time (CT) |
Turnaround time TAT = CT – AT |
Waiting time WT=TAT-BT |
A | 0 | 3 | 3 | 3 | 0 |
B | 2 | 6 | 9 | 7 | 1 |
C | 4 | 4 | 13 | 9 | 5 |
D | 6 | 5 | 20 | 14 | 9 |
E | 8 | 2 | 15 | 7 | 5 |
7. Real-Time Scheduling
Real-Time scheduling algorithm includes:
i. Rate Monotonic Algorithm (RM)
This is a fixed priority algorithm and follows the philosophy that higher priority is given to tasks with higher frequencies. Likewise, the lower priority is assigned to tasks with lower frequencies. The scheduler at any time always chooses the highest priority task for execution. By approximating to a reliable degree the execution times and the time that it takes for system handling functions, the behavior of the system can be determined a priority.
ii. Earliest Deadline First Algorithm(EDF)
This algorithm takes the approach that tasks with the closest deadlines should be meted out the highest priorities. Likewise, the task with the latest deadline has the lowest priority. Due to this approach, the processor idle time is zero and so 100% utilization can be achieved.
8. Multilevel Queue
Let us take an example of a multilevel queue scheduling algorithm with five queues:
9. Multilevel Feedback Queue
The multilevel feedback queue scheduler has the following parameters: