Sie sind auf Seite 1von 10

207SE: Operating Systems, Security and Networks

Assignment
1. Consider the following set of processes, with the length of times given in milliseconds:
Process

Arrival Time

Burst Time

Priority

10

Assume that if a new process arrives at the same time that a process finishes using the
CPU, then the new process will be added to the ready queue first.
a) Draw a chart illustrating the execution of these processes using FCFS, SJF,
shortest-remaining-time-first SRTF, a non-preemptive priority (a smaller priority
number implies a higher priority), and RR (quantum = 2) scheduling.
b) What is the waiting time of each process for each of the scheduling algorithms in
part a?
c) What is the average waiting time for each of the scheduling algorithms in part a?
2. Consider the following set of processes, with the length of the CPU burst given in
milliseconds:
Process
Burst Time Priority
P1
10
3
P2
1
1
P3
2
3
P4
1
4
P5
5
2
The processes are assumed to have arrived in the order P1, P2, P3, P4, P5 all at time 0.
a) Draw four Gantt charts that illustrate the execution of these processes using the
following scheduling algorithms: FCFS, SJF, nonpreemptive priority (a smaller
priority number implies a higher priority), and RR (quantum = 1).
b) What is the turnaround time of each process for each of the scheduling algorithms
in part a?
c) What is the waiting time of each process for each of the scheduling algorithms in
part a?
1

d) Which of the algorithms in part a results in the minimum average waiting


time (over all processes)?
3. Which of the following scheduling algorithms could result in starvation?
a) First-come, first-served b) Shortest job first
c) Round robin
d) Priority

Question 1 (a, b, c)

First Come First Serve (FCFS)

A=4

C=2
B=6A=3 B=6
A=2

C=2
D=5
B=6A=1 C=2
B=6

D=5
C=2
B=5

D=5
C=2
B=4

D=5
C=2
B=3

D=5
C=2
B=2

D=5
C=2
B=1

E=3
D=5
C=2

E=3
D=5

E=3
D=4

E=3
D=3

E=3

E=2

E=1

20

D
12

10

E=3
D=1

17

E=3
D=2

12

10

A
0

E=3
D=5
C=1

E
17

20

Shortest Job First (SJF)


A=4

C=2
A=1

D=5
C=1

A
0

C
4

E=3

B=6

11

14

D
6

E
11

20

B
14

20

Shortest Remaining First-Time (SRFT)

A=4

C=2
B=6A=3 B=6
A=2

C=2
B=6
A=1

C=2
B=6

A
0

D=5
C=1
B=6

D=5
B=6

E=3
B=6

B=6

11

14

C
4

20

11

20

14

A Non Preemptive Priority (NPP) (Smaller priority implies higher priority)


3

A=4

1
B=6

E=3

C=2

10

13

A
0

B
4

E
10

4
D=5

15

C
13

20

D
15

20

Round Robin (RR quantum 2)

A=4

C=2
B=6
A=2

C=2
B=4
A=2

D=5
B=6
A=2

D=5
B=4

A
0

B
2

C
4

A
6

E=3
D=5
B=2

E=3
D=3
B=2

E=1
D=3
B=2

E=1
D=3

E=1
D=1

D=1

10

12

14

16

18

19

B
8

D
10

E
12

B
14

D
16

E
18

19

20

D
20

Waiting Time for each of the scheduling algorithms.

FCFS*

SJF*

13

SRTF*

13

NPP*

11

10

RR*

10

Average Time for each of the scheduling algorithms.


i)

First Come First Serve (FCFS)

= 0+3+8+7+7
= 25 / 5

**
FCFS = First Come First Serve
SFJ = Shortest Job First
SRTF = Shortest Remaining
.
Time First
NPP = Non-Preemptive
.
Priority
RR = Round Robin

= 5 n/s

ii)

Shortest Job First (SJF)

= 0 + 13 + 2 + 1 +1
= 17 / 5
= 3.4 n/s

iii)

Shortest Remaining Time First

= 0 + 13 + 2 + 1 +1

(SRTF)

= 17 / 5
= 3.4 n/s

iv)

Non - Preemptive Priority (NPP) = 0 + 3 + 11 + 10 + 0


= 24 / 5
= 4.8 n/s

v)

Round Robin (RR)

= 4 + 9 + 2 + 10 + 6
= 31 / 5
= 6.2 n/s

Question 2 (a, b, c, d)
First Come First Serve (FCFS)
P5=5
P4=1
P3=2
P2=1
P1=10

P5=5
P4=1
P3=2
P2=1

10

P1

P1

P1

P1

P1

P1

P1

P1

P1

P1
10

P5=5
P4=1
P3=2

P5=5
P4=1

P5=5

11

13

14

P2

P3

11

P3
13

P4

19

P5

P5

P5

P5

14

P5
19

Shortest Job First (SJF)


P5=5
P4=1
P3=2
P2=1
P1=10

P5=5
P4=1
P3=2
P1=10

P2
0

P5=5
P3=2
P1=10

P5=5
P1=10

P1=10

P4
2

P3

P3
4

P5

P5

P5

P5

P5

19

P1

P1

P1

P1

P1

P1

P1

P1

P1

P1
19

Non Preemptive Priority (if P1 is schedule first)


P5=5
P4=1
P3=2
P2=11
P1=10

P5=52
P4=1
P3=2
P1=10

P2

P4=1
P3=2
P1=103

P5

P5

P5

P5

P5

P1

P1

P1

P1

P1

P1

P1

P1

P1

P4=1
P3=23

P4=1

16

18

P1

P3

P3
18

16

19

P4
19

Round Robin (RR Quantum 1)


P5=5
P4=1
P3=2
P2=1
P1=10

P5=5
P4=1
P3=2
P2=1
P1=9

P5=5
P4=1
P3=2
P1=9

P5=5
P4=1
P3=1
P1=9

P5=5
P3=1
P1=9

P5=4
P3=1
P1=9

P5=4
P3=1
P1=8

P1
0

P2
2

P3
3

P4
4

P5
5

P1
6

P5=4
P1=8

P5=3
P1=8

P5=3
P1=7

P3
7

P5
8

P1

P5=2
P1=7

10

P5

10

P5=2
P1=6

11

P1
11

P5=1
P1=6

P5=1
P1=5

P1=5

P1=4

P1=3

P1=2

P1=1

12

13

14

15

16

17

18

P5
12

P1
13

P5
14

P1
15

P1
16

P1
17

P1
18

19

P1
19

Turnaround times of each process for each of the scheduling algorithms.

Turnaround

(NPP) (if P1

(RR

scheduled first)

Quantum 1)

19

16

19

11

P3

13

18

P4

14

19

P5

19

14

(FCFS)

(SJF)

P1

10

P2

Times

Waiting Times for each process for each of the scheduling algorithms.

(NPP) (if P1

(RR

scheduled first)

Quantum 1)

10

P3

11

16

P4

13

18

P5

14

Waiting Times

(FCFS)

(SJF)

P1

P2

Minimum Average Waiting Time


Average Waiting Time (AWT)
(FCFS)

0 + 10 + 11 + 13 + 14 = 48

48 / 5 = 9.6 n/s
(SJF)

9 + 0 + 2 + 1 + 4 = 16
16 / 5 = 3.2 n/s

(NPP)

6 + 0 + 16 + 18 + 1 = 41

(if P1 is schedule first)

41 / 5 = 8.2 n/s

(RR Quantum 1)

9 + 1 + 5 + 3 + 9 = 27
27 / 5 = 5.4 n/s

Shortest Job First (SJF) is the answer

Question 3
Scheduling algorithm could result in starvation:
a) First Come First Served (FCFS)
b) Shortest Job First (SJF)
d) Priority

Das könnte Ihnen auch gefallen