207se: operating systems, security and networks assignment 1

Post on 23-Oct-2015

70 Views

Category:

Documents

13 Downloads

Preview:

Click to see full reader

DESCRIPTION

assignment ni bukannya hebat sgt...tapi kalo nk refer sket2 bole la

TRANSCRIPT

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

A 0 4 3

B 1 6 1

C 2 2 3

D 5 5 4

E 10 3 2

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 thefollowing 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 algorithmsin part a?

c) What is the waiting time of each process for each of the scheduling algorithms inpart 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 firstc) Round robin                       d) Priority

2

Question 1 (a, b, c)

First Come First Serve (FCFS)

A B C D E

Shortest Job First (SJF)

A C D E B

3

A=4 C=2A=1

D=5C=1 E=3 B=6

0

0

4

4

6

6

11

11 14

14 20

20

A=4B=6A=3

C=2B=6A=2

C=2B=6A=1

D=5C=2B=6

D=5C=2B=5

D=5C=2B=4

D=5C=2B=3

D=5C=2B=2

E=3D=5C=2

D=5C=2B=1

E=3D=5C=1

E=3D=5

E=3D=4

E=3D=3

E=3D=2

E=3D=1 E=3 E=2 E=1

0

0

4

4 10

10

12

12

17

17

20

20

Shortest Remaining First-Time (SRFT)

A C D E B

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

A B E C D

4

A=4B=6A=3

C=2B=6A=2

C=2B=6A=1

C=2B=6

D=5C=1B=6

D=5B=6

E=3B=6 B=6

0

0 1

1

2

2

4

4

6

6

11

11

14

14

20

20

A=4 B=6

1

E=3

2

C=2

3

D=5

4

0

0

4

4

10

10

13

13

15

15

20

20

Round Robin (RR – quantum 2)

A B C A B D E B D E D

5

A=4

0 2 4 6 8 10 12 14 16 18 19 20

0 2 4 6 8 10 12 14 16 18 19 20

C=2B=6A=2

C=2B=4A=2

D=5B=6A=2

D=5B=4

E=3D=5B=2

E=3D=3B=2

E=1D=3B=2

E=1D=3

E=1D=1 D=1

Waiting Time for each of the scheduling algorithms.

A B C D E

FCFS* 0 3 8 7 7

SJF* 0 13 2 1 1

SRTF* 0 13 2 1 1

NPP* 0 3 11 10 0

RR* 4 9 2 10 6

Average Time for each of the scheduling algorithms.

i) First Come First Serve (FCFS) = 0 + 3 + 8 + 7 + 7

= 25 / 5

= 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

6

**FCFS = First Come First ServeSFJ = Shortest Job FirstSRTF = Shortest Remaining . Time FirstNPP = Non-Preemptive . PriorityRR = Round Robin

Question 2 (a, b, c, d)

First Come First Serve (FCFS)

P1 P1 P1 P1 P1 P1 P1 P1 P1 P1 P2 P3 P3 P4 P5 P5 P5 P5 P5

Shortest Job First (SJF)

P2 P4 P3 P3 P5 P5 P5 P5 P5 P1 P1 P1 P1 P1 P1 P1 P1 P1 P1

5

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

0 10

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

P5=5P4=1P3=2

11

P5=5P4=1

13 14 19

P5=5

0 10 11 13 14 19

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

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

P5=5P3=2P1=10

P5=5P1=10

P1=10

0 1 2 4 9 19

0 1 2 4 9 19

Non – Preemptive Priority (if P1 is schedule first)

P2 P5 P5 P5 P5 P5 P1 P1 P1 P1 P1 P1 P1 P1 P1 P1 P3 P3 P4

Round Robin (RR – Quantum 1)

P1 P2 P3 P4 P5 P1 P3 P5 P1 P5 P1 P5 P1 P5 P1 P1 P1 P1 P1

5

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

P1=10

P5=52

P4=1P3=2P1=10

P4=1P3=2P1=103

P4=1P3=23 P4=1

0 1 6 16 18 19

0 1 6 16 18 19

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

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

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

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

P5=5P3=1P1=9

P5=4P3=1P1=9

P5=4P1=8

P5=3P1=8

P5=3P1=7

P5=2P1=7

P5=2P1=6

P5=1P1=6

P5=1P1=5 P1=5 P1=4 P1=3 P1=2

P5=4P3=1P1=8 P1=1

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

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

Turnaround

Times (FCFS) (SJF)

(NPP) (if P1

scheduled first)

(RR –

Quantum 1)

P1 10 19 16 19

P2 11 1 1 2

P3 13 4 18 7

P4 14 2 19 4

P5 19 9 6 14

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

Waiting Times (FCFS) (SJF)(NPP) (if P1

scheduled first)

(RR –

Quantum 1)

P1 0 9 6 9

P2 10 0 0 1

P3 11 2 16 5

P4 13 1 18 3

P5 14 4 1 9

8

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)

(if P1 is schedule first)

6 + 0 + 16 + 18 + 1 = 41

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

8

top related