Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 3

Priority Scheduling: This method is quite same as the SJF but the difference is that instead

of choosing the next process to work on by the shortest burst time, CPU chooses the next process by the
shortest priority value. Here, all the processes are given a priority value. The process with the shortest
(The most shortest is 1) priority will be worked on first and so on. Now consider a CPU and also consider
a list in which the processes are listed as follows,

Arrival Process Burst Time Priority


0 1 3 2
1 2 2 1
2 3 1 3

Here, Arrival is the time when the process has arrived the list, Process Number is used instead of the
process name, Burst Time is the amount of time required by the process from CPU, Priority value is what
we described in the first paragraph. Well, as the unit of time you can take anything like nano-second,
second, minute etc whatever. We consider it as second.

Now for an instance, consider the above list as the ready queue for the CPU, that is the CPU will take
processes from this list and will process it.

Here in Priority Scheduling, what will happen is as follows,

AT 0s:
There is only 1 job, that is Process-1 with Burst Time 3 and Priority 2. So CPU will do 1 second
job of Process-1. Thus Process-1 has 2s more job to be done.

AT 1s:
Now there are 2 jobs,
Process-1 that arrived at 0s and has 2s job to be done with Priority 2.
Process-2 that arrived at 1s and has 2s job to be done with Priority 1.

Here, Priority of the job Process-2 is higher (Lower value of priority is higher, that is shortest
priority value is higher), So 1s job of Process-2 will be done. Thus process-2 has more 1s job.

AT 2s:
Now there are 3 jobs,
Process-1 that arrived at 0s and has 2s job to be done with Priority 2.
Process-2 that arrived at 1s and has 1s job to be done with Priority 1.
Process-3 that arrived at 2s and has 1s job to be done with Priority 3.
Here, Process-2 has the highest priority, thus CPU will do 1s job of Process-2. So process-2 has
more 0s job.

AT 3s:
Now there are 2 jobs,
Process-1 that arrived at 0s and has 2s job to be done with Priority 2.
Process-3 that arrived at 2s and has 1s job to be done with Priority 3.

Here, as Process-1 is with the highest priority (which is 2) so CPU will do 1s job of Process-1. So
process-1 has more 1s job.

AT 4s:
There are 2 jobs,
Process-1 that arrived at 0s and has 1s job to be done with Priority 2.
Process-3 that arrived at 2s and has 1s job to be done with Priority 3.

Again, CPU will do 1s job of Process-1 as it is with the highest priority. Thus Process-1 has 0s
more job to be done.

AT 5s:
There is only 1 job, that is Process-3 with burst time 1 and priority 3. So CPU will do 1s job of
Process-3. Thus Process-3 has 0s more job to be done.

All Job Done.

We can show the above thing as the following time-line

Process-1 Process-2 Process-2 Process-1 Process-1 Process-3


0s 1s 2s 3s 4s 5s

A shortened view of the above time-line is as follows,

| Process-1 | Process-2 | Process-1 | Process-3 |


0 1 3 5 6

So now came the main thing, Waiting Time. Ok, Look carefully,

See the following time-line for Process-1. Here, RED marked seconds symbolizes the seconds while
Process-1 was waiting and GREEN marked second symbolizes the seconds while Process-1 was
working.
Process-1 Process-2 Process-2 Process-1 Process-1 Process-3
0s 1s 2s 3s 4s 5s

Thus Process-1 waited for 2 seconds.

Process-2 did not wait, it came at 1s and worked at 1s and 2s.

But Process-3 Arrived at the List of Process at 2s with a Burst Time of 1s. But CPU started processing
Process-3 at 5s. So process-3 waited for 3s.

Process-1 Process-2 Process-2 Process-1 Process-1 Process-3


0s 1s 2s 3s 4s 5s

So total waiting time = (Waiting Time of Process-1)+ (Waiting Time of Process-2)


+ (Waiting Time of Process-3)
= (2+0+3)s
= 5s

So the average waiting time is = (Total waiting time / Number of Processes)s


= (5/3)s
= 1.66s

You might also like