Priority Based Process Scheduling (Preemptive/Non-preemptive)

Priority based (Non-preemptive) Process Scheduling: Priority can be internal or external and static or dynamic. This algorithm selects process with highest priority to execute.

Example: Consider the following table:

Process no.

Arrival Time

Burst Time

Priority

P1

0

6

2

P2

2

1

4 (Lowest)

P3

4

4

1 (Highest)

P4

5

3

3

Find the average waiting time and average turn arround time using Priority(Non-preemptive) algorithm?

Solution: Using Priority(non-preemptive) algorithm, gantt chart is:

23.jpg

 

Therefore,
 

Waiting Time

Turn around Time

Completion Time

Process No.

Arrival Time

Burst Time

Priority

6 - 6 = 0

6 - 0 = 6

6

P1

0

6

2

12 - 1 = 11

14 - 2 = 12

14

P2

2

1

4 (Lowest)

6 - 4 = 2

10 - 4 = 6

10

P3

4

4

1 (highest)

8 - 3 = 5

13 - 5 = 8

13

P4

5

3

3

 

So,
Average Turn arround time  = (6 + 12 + 5 + 8) / (4) = 8

Average Waiting time = (0 + 11 + 2 + 5) / (4) = 4.5

Priority based (preemptive) Process Scheduling: This algorithm selects process with highest priority to execute and it’s preempted lower priority process.

Example: Consider the following table:

Process no.

Arrival Time

Burst Time

Priority

P1

0

6

2

P2

2

1

4 (Lowest)

P3

4

4

1 (Highest)

P4

5

3

3

Find the average waiting time and average turn arround time using Priority(Preemptive) algorithm?

Solution: Using Priority(Preemptive) algorithm, gantt chart is:

   

 

Therefore,
 

Waiting Time

Turn around Time

Completion Time

Process No.

Arrival Time

Burst Time

Priority

10 - 6 = 4

10 - 0 = 10

10

P1

0

6

2

12 - 1 = 11

14 - 2 = 12

14

P2

2

1

4 (Lowest)

4 - 4 = 0

8 - 4 = 4

8

P3

4

4

1 (highest)

7 - 3 = 4

13 - 6 = 7

13

P4

6

3

3

 

So,
Average Turn arround time  = (10 + 12 + 4 + 7) / (4) = 8.25

Average Waiting time = (4 + 11 + 0 + 4) / (4) = 4.75

 

4Comments
Vikas @vikasrajput
6 Dec 2019 11:07 pm
completion time for P3 is incorrect in the solution table, it should be 8
Rohit Panwar @panwarrohit
7 Dec 2019 12:47 am
@vikas u are right it was typo ...now it has been corrected.Thanx for make us correct.
SHIVAM KUMAR @shivamkumar12
13 Dec 2019 09:04 pm
it should be 6 in place of 5
priority (non-preemption)
Average Turn arround time = (6 + 12 + 5 + 8) / (4) = 8
SHIVAM KUMAR @shivamkumar12
13 Dec 2019 09:09 pm
in priority (preemption)
P4 arrival time is 5 . please make correction accordingly
Average Turn arround time = (10 + 12 + 4 + 7) / (4) = 8.25 // its correct answer is 8.5

Average Waiting time = (4 + 11 + 0 + 4) / (4) = 4.75 // its correct answer is 5