Priority scheduling

Post on 06-Jan-2017

242 views 0 download

transcript

Baljit Singh Saini

Priority SchedulingPre-emptive

Baljit Singh Saini

Key PointsIn priority scheduling a number is assigned

to each process which indicates its priority level.

Lower the number, higher is the priority.If a new process arrives which is having

higher priority than the currently running process, then the currently running process is preempted.

It suffers from starvation problem.“Aging” can be used to increase the priority

of a process and thus avoid starvation.

Baljit Singh Saini

Process Priority Burst Time Arrival Time

P1 1 4 0

P2 2 3 0

P3 1 7 6

P4 3 4 11

p5 2 2 12

0Timer

P1

P2 Both P1 and P2 arrive at time

ZERO

0

Which is having higher priority P1 or

P2 ?

Baljit Singh Saini

Process Priority Burst Time Arrival Time

P1 1 4/3 0

P2 2 3 0

P3 1 7 6

P4 3 4 11

p5 2 2 12

1Timer

P2

0

P1

At time 1, no new process arrives so we

continue with P1

Baljit Singh Saini

Process Priority Burst Time Arrival Time

P1 1 4/2 0

P2 2 3 0

P3 1 7 6

P4 3 4 11

p5 2 2 12

2Timer

P2

0

P1

At time 2, no new process arrives so we

continue with P1

Baljit Singh Saini

Process Priority Burst Time Arrival Time

P1 1 4/1 0

P2 2 3 0

P3 1 7 6

P4 3 4 11

p5 2 2 12

3Timer

P2

0

P1

At time 3, no new process arrives so we

continue with P1

Baljit Singh Saini

Process Priority Burst Time Arrival Time

P1 1 4 0

P2 2 3 0

P3 1 7 6

P4 3 4 11

p5 2 2 12

4Timer

P2

0

P1

At time 4, P1 has finished its

processing, so processor is assigned

to P2 now.

4

Baljit Singh Saini

Process Priority Burst Time Arrival Time

P1 1 4 0

P2 2 3/2 0

P3 1 7 6

P4 3 4 11

p5 2 2 12

5Timer

0

P1

4

P2

At time 5, no new process arrives so we

continue with P2

Baljit Singh Saini

Process Priority Burst Time Arrival Time

P1 1 4 0

P2 2 3/1 0

P3 1 7 6

P4 3 4 11

p5 2 2 12

6Timer

0

P1

4

P2

At time 6, P3 arrives P3

Which is higher priority process P2 or

P3?

6

P2 is preempted and P3 starts executing

Baljit Singh Saini

Process Priority Burst Time Arrival Time

P1 1 4 0

P2 2 3/1 0

P3 1 7 6

P4 3 4 11

p5 2 2 12

6Timer

0

P1

4

P2

P2

6

P3

System state at time 6

Baljit Singh Saini

Process Priority Burst Time Arrival Time

P1 1 4 0

P2 2 3/1 0

P3 1 7/6 6

P4 3 4 11

p5 2 2 12

7Timer

0

P1

4

P2

6

P3

At time 7, no new process arrives, so we

continue with P3P2

Baljit Singh Saini

Process Priority Burst Time Arrival Time

P1 1 4 0

P2 2 3/1 0

P3 1 7/5 6

P4 3 4 11

p5 2 2 12

8Timer

0

P1

4

P2

6

P3

At time 8, no new process arrives, so we

continue with P3P2

Baljit Singh Saini

Process Priority Burst Time Arrival Time

P1 1 4 0

P2 2 3/1 0

P3 1 7/4 6

P4 3 4 11

p5 2 2 12

9Timer

0

P1

4

P2

6

P3

At time 9, no new process arrives, so we

continue with P3P2

Baljit Singh Saini

Process Priority Burst Time Arrival Time

P1 1 4 0

P2 2 3/1 0

P3 1 7/3 6

P4 3 4 11

p5 2 2 12

10Timer

0

P1

4

P2

6

P3

At time 10, no new process arrives, so we

continue with P3P2

Baljit Singh Saini

Process Priority Burst Time Arrival Time

P1 1 4 0

P2 2 3/1 0

P3 1 7/2 6

P4 3 4 11

p5 2 2 12

11Timer

0

P1

4

P2

6

P3

At time 11, P4 arrives

Process Priority Burst Time Arrival Time

P1 1 4 0

P2 2 3/1 0

P3 1 7/2 6

P4 3 4 11

p5 2 2 12

Which Process is having higher priority

P3 or P4?

Since p3 had higher priority so it

continues executionP4

P2

Baljit Singh Saini

Process Priority Burst Time Arrival Time

P1 1 4 0

P2 2 3/1 0

P3 1 7/2 6

P4 3 4 11

p5 2 2 12

12Timer

0

P1

4

P2

6

P3

At time 12, P5 arrives

Process Priority Burst Time Arrival Time

P1 1 4 0

P2 2 3/1 0

P3 1 7/1 6

P4 3 4 11

p5 2 2 12

Which Process is having higher priority

P3 or P5?

Since p3 had higher priority so it

continues executionP4

P2

P5

Baljit Singh Saini

Process Priority Burst Time Arrival Time

P1 1 4 0

P2 2 3/1 0

P3 1 7/2 6

P4 3 4 11

p5 2 2 12

13Timer

0

P1

4

P2

6

P3

At time 13, P3 is finished with its

execution

Process Priority Burst Time Arrival Time

P1 1 4 0

P2 2 3/1 0

P3 1 7/0 6

P4 3 4 11

p5 2 2 12

Which Process is having higher priority

P2, P4 or P5?

P2 and P5 are having same priorityP

4P2

P5

13

Since P2 arrived first so P2 is selected for

execution

Baljit Singh Saini

Process Priority Burst Time Arrival Time

P1 1 4 0

P2 2 3/1 0

P3 1 7/2 6

P4 3 4 11

p5 2 2 12

13Timer

0

P1

4

P2

6

P3

Process Priority Burst Time Arrival Time

P1 1 4 0

P2 2 3/1 0

P3 1 7 6

P4 3 4 11

p5 2 2 12

P4

P2

P5

13

Baljit Singh Saini

Process Priority Burst Time Arrival Time

P1 1 4 0

P2 2 3/1 0

P3 1 7/2 6

P4 3 4 11

p5 2 2 12

14Timer

0

P1

4

P2

6

P3

At time 14, P2 is finished with its

execution

Process Priority Burst Time Arrival Time

P1 1 4 0

P2 2 3/0 0

P3 1 7 6

P4 3 4 11

p5 2 2 12

P4

P2

P5

13

Baljit Singh Saini

Process Priority Burst Time Arrival Time

P1 1 4 0

P2 2 3/1 0

P3 1 7/2 6

P4 3 4 11

p5 2 2 12

14Timer

0

P1

4

P2

6

P3

At time 14, P2 is finished with its

execution

Process Priority Burst Time Arrival Time

P1 1 4 0

P2 2 3 0

P3 1 7 6

P4 3 4 11

p5 2 2 12

P4

P2

P5

13

14

Out of P4 and P5, P5 is having higher

priority

Baljit Singh Saini

Process Priority Burst Time Arrival Time

P1 1 4 0

P2 2 3/1 0

P3 1 7/2 6

P4 3 4 11

p5 2 2 12

15Timer

0

P1

4

P2

6

P3

Process Priority Burst Time Arrival Time

P1 1 4 0

P2 2 3 0

P3 1 7 6

P4 3 4 11

p5 2 2/1 12

P4

P2

P5

13

14

Baljit Singh Saini

Process Priority Burst Time Arrival Time

P1 1 4 0

P2 2 3/1 0

P3 1 7/2 6

P4 3 4 11

p5 2 2 12

16Timer

0

P1

4

P2

6

P3

Process Priority Burst Time Arrival Time

P1 1 4 0

P2 2 3 0

P3 1 7 6

P4 3 4 11

p5 2 2/0 12

P4

P2

13

14

At time 16, P5 is finished with its

execution

P5

Baljit Singh Saini

Process Priority Burst Time Arrival Time

P1 1 4 0

P2 2 3/1 0

P3 1 7/2 6

P4 3 4 11

p5 2 2 12

16Timer

0

P1

4

P2

6

P3

Process Priority Burst Time Arrival Time

P1 1 4 0

P2 2 3 0

P3 1 7 6

P4 3 4 11

p5 2 2 12

P4

P2

13

14

At time 16, P5 is finished with its

execution

P5

16

P4 is the only process left

Baljit Singh Saini

Process Priority Burst Time Arrival Time

P1 1 4 0

P2 2 3/1 0

P3 1 7/2 6

P4 3 4 11

p5 2 2 12

17Timer

0

P1

4

P2

6

P3

Process Priority Burst Time Arrival Time

P1 1 4 0

P2 2 3 0

P3 1 7 6

P4 3 4/3 11

p5 2 2 12

P4

P2

13

14

P5

16

Baljit Singh Saini

Process Priority Burst Time Arrival Time

P1 1 4 0

P2 2 3/1 0

P3 1 7/2 6

P4 3 4 11

p5 2 2 12

18Timer

0

P1

4

P2

6

P3

Process Priority Burst Time Arrival Time

P1 1 4 0

P2 2 3 0

P3 1 7 6

P4 3 4/2 11

p5 2 2 12

P4

P2

13

14

P5

16

Baljit Singh Saini

Process Priority Burst Time Arrival Time

P1 1 4 0

P2 2 3/1 0

P3 1 7/2 6

P4 3 4 11

p5 2 2 12

19Timer

0

P1

4

P2

6

P3

Process Priority Burst Time Arrival Time

P1 1 4 0

P2 2 3 0

P3 1 7 6

P4 3 4/1 11

p5 2 2 12

P4

P2

13

14

P5

16

Baljit Singh Saini

Process Priority Burst Time Arrival Time

P1 1 4 0

P2 2 3/1 0

P3 1 7/2 6

P4 3 4 11

p5 2 2 12

20Timer

0

P1

4

P2

6

P3

Process Priority Burst Time Arrival Time

P1 1 4 0

P2 2 3 0

P3 1 7 6

P4 3 4/0 11

p5 2 2 12

P4

P2

13

14

P5

16

20

Baljit Singh Saini

Process Priority Burst Time Arrival Time

P1 1 4 0

P2 2 3/1 0

P3 1 7/2 6

P4 3 4 11

p5 2 2 12

20Timer

0

P1

4

P2

6

P3

Process Priority Burst Time Arrival Time

P1 1 4 0

P2 2 3 0

P3 1 7 6

P4 3 4 11

p5 2 2 12

P4

P2

13

14

P5

16

20

Baljit Singh Saini

Process Priority Burst Time Arrival Time

P1 1 4 0

P2 2 3/1 0

P3 1 7/2 6

P4 3 4 11

0

P1

4

P2

6

P3

Process Priority Burst Time Arrival Time

P1 1 4

P2 2 3

P3 1 7

P4 3 4 11

p5 2 2 12

P4

P2

13

14

P5

16

20

Waiting Time = Start time – arrival time + wait time for next burst

P1 =

0 – 0 = 0

0

P2 =

0

4 – 0 + 7 = 11 P3 =

6

6 - 6 = 0 P4 = 16 – 11 = 5P5 = 14 – 12 = 2

Av. Waiting time = (0+11+0+5+2)/5 = 18/5 = 3.6