PROBLEMS of Operating System Unit: 02
Before going to problems we will discuss some
abbreviations and their meaning are as follows: 
1. TAT Turn
Around Time
2. BT Burst
Time
3. AT Arrival
Time
4. WT Waiting
Time
5. FT/CT Finish
Time / Completion Time
Some basic formula
that we use: 
1. Turn Around Time(TAT) = Completion time (CT)
– Arrival Time (AT)
2. Waiting Time (WT) = Turn Around Time (TAT) –
Burst Time (BT)
Problem 1.1: 
Consider the following snapshot of an OS with 5
processes:
Process

Arrival Time

Burst time

P0

0

2

P1

2

3

P2

4

6

P3

6

4

P4

8

5

Compute and prepare a chart for Average Waiting time
and Average Turnaround time of each process for algorithm: 
1. FCFS
2. SJF
3. Round
Robin (Quantum = 2)
SOLUTION: 
1. Using FCFS: 
Using
FCFS first we have to prepare GANTT
CHART which is as follow: 
Gantt chart: 
Now we can say that: 
1.
2 is the completion time of P0 (process 0)
2.
5 is the completion time of P1 (processn1)
3.
11 is the completion time of P2 (process 2)
4.
15 is the completion time of P3 (process 3)
5.
20 is the completion time of P4 (process 4)
Process

AT

BT

CT

TAT=CTAT

WT=TATBT

P0

0

2

2

20= 2

22= 0

P1

2

3

5

52= 3

33= 0

P2

4

6

11

114= 7

76= 1

P3

6

4

15

156= 9

94= 5

P4

8

5

20

208= 12

125= 7

Total
number of process= 5

TAT= 33

WT= 13

Average
Turnaround Time= Total TAT/ Number of process
=
(33/5)
=6.6
Milliseconds
Average
Turnaround Time= Total WT/ Number of process
=
(13/5)
=2.6
Milliseconds
2. Using SJN (preemptive type): 
Using
SJN first we have to prepare GANTT CHART
which is as follow: 
Gantt chart: 
NOTE:  First
add smallest AT and it’s BT, then
selects the smallest BT from the
table in ascending order and prepare GANTT
CHART.
Now we can say that: 
1.
2 is the completion time of P0 (process 0)
2.
5 is the completion time of P1 (processn1)
3.
20 is the completion time of P2 (process 2)
4.
9 is
the completion time of P3 (process 3)
5.
14 is the completion time of P4 (process 4)
Process

AT

BT

CT

TAT=CTAT

WT=TATBT

P0

0

2

2

20= 2

22= 0

P1

2

3

5

52= 3

33= 0

P2

4

6

20

204= 16

166= 10

P3

6

4

9

96= 3

34= 1

P4

8

5

14

148= 6

65= 1

Total
number of process= 5

TAT= 30

WT= 12

Average
Turnaround Time= Total TAT/ Number of process
=
(30/5)
=6.0
Milliseconds
Average
Turnaround Time= Total WT/ Number of process
=
(12/5)
=2.4
Milliseconds
3. Round Robin (Quantum time/timeslice= 2)
Now we can say that: 
1.
2 is the completion time of P0 (process 0)
2.
11 is the completion time of P1 (processn1)
3.
19 is the completion time of P2 (process 2)
4.
15 is the completion time of P3 (process 3)
5.
20 is the completion time of P4 (process 4)
Process

AT

BT

CT

TAT=CTAT

WT=TATBT

P0

0

2

2

20= 2

22= 0

P1

2

3

11

112= 9

93= 6

P2

4

6

19

194= 15

156= 9

P3

6

4

15

156= 9

94= 5

P4

8

5

20

208= 12

125= 7

Total
number of process= 5

TAT= 47

WT= 27

Average
Turnaround Time= Total TAT/ Number of process
=
(47/5)
=9.4
Milliseconds
Average
Turnaround Time= Total WT/ Number of process
=
(27/5)
=5.4
Milliseconds
Problem 1.2: (Try yourself)
Consider the following snapshot of an OS with 5
processes:
Process

Arrival Time

CPU Burst time

P0

0

4

P1

1

6

P2

3

3

P3

9

6

P4

12

6

Compute and prepare a chart for Average Waiting time
and Average Turnaround time of each process for algorithm: 
1. FCFS
2. SJF
3. Round
Robin (Quantum = 2)
Answer: 
1. FCFS: 
Answer: 
1. FCFS: 
Average
Turnaround Time =9.2
Milliseconds
Average
Turnaround Time= 4.2
Milliseconds
2. SJN: 
2. SJN: 
Average
Turnaround Time =
8.6 Milliseconds
Average
Turnaround Time= 3.6
Milliseconds
3. Round Robin: 
3. Round Robin: 
Average
Turnaround Time = Milliseconds
Average
Turnaround Time= Milliseconds
Problem 1.3: (Try yourself)
Consider the following snapshot of an OS with 5
processes:
Process

Arrival Time

CPU Burst time

P0

0

3

P1

1

5

P2

3

2

P3

9

5

P4

12

5

Compute and prepare a chart for Average Waiting time
and Average Turnaround time of each process for algorithm: 
Use Nonpreemptive and Preemptive both type scheduling
1. FCFS
2. SJF
3. Round
Robin (Quantum = 2)
NOTE: Both preemptive and nonpreemptive have same result. Average waiting time for SJN is small as compare to FCFS so SJN scheduling is best.
Answer:  1. FCFS: 
Average
Turnaround Time =6.2
Milliseconds
Average
Turnaround Time= 2.2
Milliseconds
2. SJN: 
2. SJN: 
Average
Turnaround Time = 5.6 Milliseconds
Average
Turnaround Time= 1.6
Milliseconds
3. Round Robin: 
3. Round Robin: 
Average
Turnaround Time = Milliseconds
Average
Turnaround Time= Milliseconds
Problem 1.4: (Try yourself)
Consider the following snapshot of an OS with 5
processes:
Process

Arrival Time

CPU Burst time

P0

0

1

P1

1

9

P2

2

1

P3

3

9

Compute and prepare a chart for Average Waiting time
and Average Turnaround time of each process for algorithm: 
1. FCFS
2. SJF
Answer: 
1. FCFS: 
Answer: 
1. FCFS: 
Average
Turnaround Time =9.0 Milliseconds
Average
Turnaround Time= 4.0
Milliseconds
2. SJN: 
2. SJN: 
Average
Turnaround Time = 7.25 Milliseconds
Average
Turnaround Time= 2.5
Milliseconds
Problem 1.5: 
Consider the following snapshot of an OS with 5
processes:
Process

Arrival Time

CPU Burst time

P1

0

6

P2

0

8

P3

0

7

P4

0

3

Compute and prepare a chart for Average Waiting time
and Average Turnaround time of each process for algorithm: 
1.
SJF (Use Nonpreemptive Scheduling)
Solution:

Using SJF scheduling, we
would schedule these processes according to the following GANT CHART: 
Gantt
chart: 
P4

P1

P3

P2

0 3 9 16 24
The
waiting time for the above Gantt Chart is as follows: 
1.
3 milliseconds for process P1,
2.
16 milliseconds for process P2,
3.
9 milliseconds for process P3,
4.
0 milliseconds for process P4.
Average
waiting time = (3+16+9+0)/4
=
28/4
=
7 milliseconds
Similarly, we can calculate Average TAT, And FCFS AWT
& ATAT.
Problem 1.6:  (Try yourself)
Consider the following snapshot of an OS with 4
processes:
Process

Arrival Time

CPU Burst time

P1

0

8

P2

1

4

P3

2

9

P4

3

35

Compute and prepare a chart for Average Waiting time
and Average Turnaround time of each process for algorithm: 
1.
SJF (Use Nonpreemptive Scheduling)
Problem 1.7: 
Consider the following snapshot of an OS with 5
processes:
Process

Burst Time

Priority

P1

10

3

P2

1

1

P3

2

3

P4

1

4

P5

5

2

This process are assumed
to have arrived on the order P1,P2,P3,P4 and P5, all at time 0.(means arrival
time of each process is 0)
Compute and prepare a
chart for Average Waiting time and Average Turnaround time of each process for
algorithm: 
1. FCFS
2. SJF
3. Priority
scheduling
4. Round
Robin (Quantum = 2)
SOLUTION: 
In
the problem priority of processes are given but in the FCFS, SJF, and RR there
is no need of priority. We are additionally solving this problem for priority
scheduling.
Using
FCFS: 
Using FCFS first we have to prepare GANTT CHART which is as follow: 
Gantt chart: 
Now we can say that: 
1.
10 is the completion time of P1 (process 1)
2.
11 is the completion time of P2 (processn2)
3.
13 is the completion time of P3 (process 3)
4.
14 is the completion time of P4 (process 4)
5.
19 is the completion time of P5 (process 5)
Process

AT

BT

CT

TAT=CTAT

WT=TATBT

P1

0

10

10

100=10

1010= 0

P2

0

1

11

110=11

111= 10

P3

0

2

13

130=13

132= 11

P4

0

1

14

140=14

141= 13

P5

0

5

19

190=19

195= 14

Total
number of process= 5

TAT= 67

WT= 48

Average
Turnaround Time= Total TAT/ Number of process
=
(67/5)
=13.4
Milliseconds
Average
Turnaround Time= Total WT/ Number of process
=
(48/5)
=9.6
Milliseconds
Using SJN: 
Using
SJN first we have to prepare GANTT CHART
which is as follow: 
Gantt chart: 
NOTE:  First
add smallest AT and it’s BT, then
selects the smallest BT from the
table in ascending order and prepare GANTT
CHART.
Now we can say that: 
1.
19 is the completion time of P1 (process 1)
2.
1 is the completion time of P2 (processn2)
3.
4 is the completion time of P3 (process 3)
4.
2 is the completion time of P4 (process 4)
5.
9 is the completion time of P5 (process 5)
Process

AT

BT

CT

TAT=CTAT

WT=TATBT

P1

0

10

19

190=19

1910= 9

P2

0

1

1

10=1

11= 0

P3

0

2

4

40=4

42= 2

P4

0

1

2

20=2

21= 1

P5

0

5

9

90=9

95= 4

Total
number of process= 5

TAT= 35

WT= 16

Average
Turnaround Time= Total TAT/ Number of process
=
(35/5)
=7.0
Milliseconds
Average
Turnaround Time= Total WT/ Number of process
=
(16/5)
=3.2
Milliseconds
Priority Scheduling: 
Using
the priority scheduling first we have to prepare GANTT CHART, according to the priority given in the table which is as follow: 
Gantt chart: 
NOTE:  First add smallest AT and it’s BT, then selects the
smallest BT from the table in
ascending order and prepare GANTT CHART.
Now we can say that: 
1.
16 is the completion time of P1 (process 1)
2.
1 is the completion time of P2 (processn2)
3.
18 is the completion time of P3 (process 3)
4.
19 is the completion time of P4 (process 4)
5.
6 is the completion time of P5 (process 5)
Process

AT

BT

CT

TAT=CTAT

WT=TATBT

P1

0

10

16

160=16

1610= 6

P2

0

1

1

10=1

11= 0

P3

0

2

18

180=18

182= 16

P4

0

1

19

190=19

191= 18

P5

0

5

6

60=6

65= 1

Total
number of process= 5

TAT= 60

WT= 50

Average
Turnaround Time= Total TAT/ Number of process
=
(60/5)
=12.0
Milliseconds
Average
Turnaround Time= Total WT/ Number of process
=
(50/5)
=8.2 Milliseconds
1. Round Robin (Quantum time/timeslice= 2)
Quantum is allocated to each process for execution. (it
is in milliseconds)
Now
we can say that: 
1. 16
is the completion time of P1 (process 1)
2. 1
is the completion time of P2 (processn2)
3. 18
is the completion time of P3 (process 3)
4. 19
is the completion time of P4 (process 4)
5. 6
is the completion time of P5 (process 5)
Process

AT

BT

CT

TAT=CTAT

WT=TATBT

P1

0

10

19

190=19

1910= 9

P2

0

1

3

30=3

31= 2

P3

0

2

5

50=5

52= 3

P4

0

1

6

60=6

61= 5

P5

0

5

15

150=15

155= 10

Total
number of process= 5

TAT= 48

WT= 29

Average
Turnaround Time= Total TAT/ Number of process
=
(48/5)
=9.6
Milliseconds
Average
Turnaround Time= Total WT/ Number of process
=
(29/5)
=5.8
Milliseconds
Problem 1.8:  (Try yourself)
Consider the following snapshot of an OS with 5
processes:
Process

Burst Time

Priority

P1

10

3

P2

1

1

P3

2

4

P4

1

5

P5

5

2

This process are assumed
to have arrived on the order P1,P2,P3,P4 and P5, all at time 0.(means arrival time
of each process is 0)
Compute and prepare a
chart for Average Waiting time and Average Turnaround time of each process for
algorithm: 
1. FCFS
2. SJF
3. Priority
scheduling
4. Round
Robin (Quantum = 1)
Answer: 
1. FCFS: 
3. Round Robin: 
Answer: 
1. FCFS: 
Average
Turnaround Time =13.4
Milliseconds
Average
Turnaround Time= 9.6
Milliseconds
2. SJN: 
2. SJN: 
Average
Turnaround Time = 7.0 Milliseconds
Average
Turnaround Time= 3.2
Milliseconds
3. Round Robin: 
Average
Turnaround Time =9.2 Milliseconds
Average
Turnaround Time=5.4 Milliseconds
Problem 1.9: 
Consider the following snapshot of an OS with 5
processes:
Process

Arrival Time

CPU Burst time

P1

0

24

P2

0

3

P3

0

3

Compute
and prepare a chart for Average Waiting time and Average Turnaround time of
each process for algorithm RR scheduling: 
SOLUTION: 
1. If
we use a time quantum of 4 milliseconds, then process P1 gets the first 4
milliseconds. Since it requires another 20 milliseconds, it is preemptive after
the first time quantum, and the CPU is given to the process in the queue,
process P2.
2. Since
process P2 does not need 4 milliseconds, it quite before its time quantum expires.
The CPU is then given to the next process, process P3.
3. Once
each process has received 1 time quantum, the CPU is returned to the P1 process
for an additional time quantum.
4. The
resulting RR schedule is: 
Round Robin (Quantum time/timeslice= taken
as 4)
Now
we can say that: 
1.
30 is the completion time of P1 (process 1)
2.
7 is the completion time of P2 (processn2)
3.
10 is the completion time of P3 (process 3)
Process

AT

BT

CT

TAT=CTAT

WT=TATBT

P1

0

24

30

300=30

3024= 6

P2

0

3

7

70=7

73= 4

P3

0

3

10

100=10

103= 7

Total
number of process= 5

TAT= 47

WT= 17

Average
Turnaround Time= Total TAT/ Number of process
=
(47/5)
=9.4
Milliseconds
Average
Turnaround Time= Total WT/ Number of process
=
(17/5)
=3.4
Milliseconds
Problem 1.10: 
Consider the following snapshot of an OS with 5
processes:
Process

Arrival Time

Burst time

P1

0

10

P2

1

29

P3

3

3

P4

9

7

P5

12

12

Compute and prepare a chart for Average Waiting time
and Average Turnaround time of each process for algorithm: 
1. FCFS
2. SJF
3. Round
Robin (Quantum = 10 milliseconds)
Which
algorithm would give minimum AWT and ATAT?
Problem 1.11: 
Consider the following snapshot of an OS with 5
processes:
Process

Arrival Time

Burst time

P1

0

1

P2

1

9

P3

2

1

P4

3

9

P5

3

9

Compute and prepare a chart for Average Waiting time
and Average Turnaround time of each process for algorithm: 
1. FCFS
2. SJF
3. Round
Robin (Quantum = 4 milliseconds)
Problem 1.11: 
Consider the following snapshot of an OS with 5
processes:
Process

Arrival Time

Burst time

Priority

P1

0

4

6

P2

1

5

5

P3

2

2

3

P4

3

1

4

P5

4

3

2

P6

5

6

1

Compute and prepare a chart for Average Waiting time
and Average Turnaround time of each process for algorithm: 
1. FCFS
2. SJF
3. Priority
4. Round
Robin (Quantum = 4 milliseconds)
For any problem you can comment we will definitely reply on your problems.
(Note: Update available soon, comment for any type of help)
{Other links
COA : 
OS
ISP: 
https://diplomaforcse.blogspot.com/2019/08/previousyearquestionforcomputer_31.html
CPTC
NOTES of COA (unit1): 
NOTES of ISP (unit4): 
NOTES of OS (unit1): 
https://diplomaforcse.blogspot.com/2019/11/notesforcomputerscienceand.htmlScheduling algorithm numerical click me
}
FOLLOW US ON FACEBOOK:
Sir,try urself ques ans??
ReplyDeleteOk I will upload it, within some days
ReplyDelete