shortest job first (preemptive) scheduling

21

Click here to load reader

Upload: baljitsaini28

Post on 06-Jan-2017

1.191 views

Category:

Engineering


4 download

TRANSCRIPT

Page 1: Shortest job first (preemptive) scheduling

SJF(Shortest Job First)Pre-emptive

Baljit Singh Saini

Page 2: Shortest job first (preemptive) scheduling

Key points

• Also called Shortest Remaining Time First• Suffers from starvation problem

Page 3: Shortest job first (preemptive) scheduling

process Burst time Arrival time

P1 6 2

P2 2 5

P3 8 1

P4 3 0

P5 4 4

P40

0

Baljit Singh Saini

Page 4: Shortest job first (preemptive) scheduling

process Burst time Arrival time

P1 6 2

P2 2 5

P3 8 1

P4 3/2 0

P5 4 4

P4

1

0

P3

Baljit Singh Saini

Page 5: Shortest job first (preemptive) scheduling

process Burst time Arrival time

P1 6 2

P2 2 5

P3 8 1

P4 3/1 0

P5 4 4

P4

2

0

P3 P1

Baljit Singh Saini

Page 6: Shortest job first (preemptive) scheduling

process Burst time Arrival time

P1 6 2

P2 2 5

P3 8 1

P4 3 0

P5 4 4

P4

3

0

P3 P1

3

Baljit Singh Saini

Page 7: Shortest job first (preemptive) scheduling

process Burst time Arrival time

P1 6 2

P2 2 5

P3 8 1

P4 3 0

P5 4 4

P4

3

0

P3 P1

3

Baljit Singh Saini

Which is Smaller Job:P3 or P1 ?

Page 8: Shortest job first (preemptive) scheduling

process Burst time Arrival time

P1 6/5 2

P2 2 5

P3 8 1

P4 3 0

P5 4 4

P4

4

0

P1

P3

3

P5

Baljit Singh Saini

Which is Smaller Job:P3, P5 or P1 ?

4

Page 9: Shortest job first (preemptive) scheduling

process Burst time Arrival time

P1 6/5 2

P2 2 5

P3 8 1

P4 3 0

P5 4/3 4

P4

5

0

P1

P3

3

P5

Baljit Singh Saini

4

P2

Which is Smaller Job:P3, P5 or P2 ?

5

P1

Page 10: Shortest job first (preemptive) scheduling

process Burst time Arrival time

P1 6/5 2

P2 2 5

P3 8 1

P4 3 0

P5 4/3 4

P4

6

0

P1

P3

3

P5

Baljit Singh Saini

4

P2

5

P1 P5

Page 11: Shortest job first (preemptive) scheduling

process Burst time Arrival time

P1 6/5 2

P2 2 5

P3 8 1

P4 3 0

P5 4/3 4

P4

7

0

P1

P3

3

P5

Baljit Singh Saini

4

P2

5 7

P1 P5

Page 12: Shortest job first (preemptive) scheduling

process Burst time Arrival time

P1 6/5 2

P2 2 5

P3 8 1

P4 3 0

P5 4/3 4

P4

7

0

P1

P3

3

P5

Baljit Singh Saini

4

P2

5 7

P1 P5

Which is Smaller Job:P3, P5 or P1 ?

Page 13: Shortest job first (preemptive) scheduling

process Burst time Arrival time

P1 6/5 2

P2 2 5

P3 8 1

P4 3 0

P5 4/2 4

P4

8

0

P1

P3

3

P5

Baljit Singh Saini

4

P2

5 7

P1

P5

Page 14: Shortest job first (preemptive) scheduling

process Burst time Arrival time

P1 6/5 2

P2 2 5

P3 8 1

P4 3 0

P5 4/1 4

P4

9

0

P1

P3

3

P5

Baljit Singh Saini

4

P2

5 7

P1

P5

Page 15: Shortest job first (preemptive) scheduling

process Burst time Arrival time

P1 6/5 2

P2 2 5

P3 8 1

P4 3 0

P5 4 4

P4

10

0

P1

P3

3

P5

Baljit Singh Saini

4

P2

5 7

P1

P5

10

Page 16: Shortest job first (preemptive) scheduling

process Burst time Arrival time

P1 6/5 2

P2 2 5

P3 8 1

P4 3 0

P5 4 4

P4

10

0

P1

P3

3

P5

Baljit Singh Saini

4

P2

5 7

P1

P5

10

Page 17: Shortest job first (preemptive) scheduling

process Burst time Arrival time

P1 6/4 2

P2 2 5

P3 8 1

P4 3 0

P5 4 4

P4

11

0

P1

P3

3

P5

Baljit Singh Saini

4

P2

5 7

P1P5

10

Page 18: Shortest job first (preemptive) scheduling

process Burst time Arrival time

P1 6/../0 2

P2 2 5

P3 8 1

P4 3 0

P5 4 4

P4

15

0

P1

P3

3

P5

Baljit Singh Saini

4

P2

5 7

P1P5

10 15

Page 19: Shortest job first (preemptive) scheduling

process Burst time Arrival time

P1 6 2

P2 2 5

P3 8 1

P4 3 0

P5 4 4

P4

23

0

P1 P3

3

P5

Baljit Singh Saini

4

P2

5 7

P1P5

10 15 23

Page 20: Shortest job first (preemptive) scheduling

process Burst time Arrival time

P1 6 2

P2 2 5

P3 8 1

P4 3 0

P5 4 4

P4

23

0

P1 P3

3

P5

Baljit Singh Saini

4

P2

5 7

P1P5

10 15 23

Page 21: Shortest job first (preemptive) scheduling

process Burst time Arrival time

P1 6 2

P2 2 5

P3 8 1

P4 3 0

P5 4 4

P4

0

P1 P3

3

P5

Baljit Singh Saini

4

P2

5 7

P1P5

10 15 23

Waiting time = Start time – Arrival time + wait time for next burstP4 = 0 - 0 = 0

P1 = (3 - 2 ) +

P2 = 5 - 5 = 0P5 = 4 – 4+2 = 2P3 = 15 - 1 = 14

Av. Waiting Time = 6 = 7

P1 waited for next burst