In: Computer Science
Consider the following set of processes, with the length of the CPU-burst time given in milliseconds:
Process |
Burst Time |
Priority |
Arrival Time |
P1 |
10 |
3 |
0 |
P2 |
1 |
1 |
12 |
P3 |
2 |
4 |
0 |
P4 |
1 |
5 |
0 |
P5 |
5 |
2 |
0 |
In the above table, a smaller priority number implies a higher priority. Suppose that these processes are scheduled by the priority policy with preemption.
In Priority Scheduling, we run the process first which has higher priority.
In Preemption, CPU scheduling algo is invoked under 3 conditions,
When a process wishes to perform I/O . Therefore, CPU scheduling algo is invoked to select a next new process.
When a process terminates and therefore CPU scheduling algo is invoked
When a process is forcefully removed from the CPU.(Process voluntarily leaves)
here, Process will interrupt only when it is interrupted or when a process of higher priority is waiting in ready queue.
a) Gantt chart is the chart which shows the sequence in which process was completed.
THE GANTT CHART IS:
P5 | P1 | P2 | P1 | P3 | P4 |
0 5 12 13 16 18 19 ------- TIME
On the basis of the gantt chart we can find completion time, Turn Around Time and Waiting Time
PROCESS | PRIORITY | ARRIVAL TIME | BURST TIME | COMPLETION TIME | TURN AROUND TIME | WAITING TIME |
P1 | 3 | 0 | 10 | 16 | 16 | 6 |
P2 | 1 | 12 | 1 | 13 | 1 | 0 |
P3 | 4 | 0 | 2 | 18 | 18 | 16 |
P4 | 5 | 0 | 1 | 19 | 19 | 18 |
P5 | 2 | 0 | 5 | 5 | 5 | 0 |
b) Waiting Time of P1, P2, P3, P4, P5 are 6, 0, 16, 18, 0
c) Average Waiting Time = ( 6 + 0 + 16 + 18 + 0 ) / 5
= 40 / 5
= 8 milliseconds