Os Past Papers' Solutions 2019

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

PAST PAPERS’ SOLUTIONS

YEAR 2019

Q # 3 (a):
Solve the following question using Banker’s algorithm.

Process Allocation Max Available


A B C D A B C D A B C D
P0 0 1 0 0 0 5 1 3 1 3 2 2
P1 1 0 0 0 1 2 5 2
P2 1 0 5 2 2 0 5 2
P3 0 1 3 1 0 2 5 2
P4 0 0 1 2 0 3 5 3
i. What is the content of need matrix?
ii. Is the system in safe state?

Solution:
Total Available Resources: Available + Allocated
= (1, 3, 2, 2) + (2, 2, 9, 5)
= (3, 5, 11, 7)

Need Matrix:
Process Need (Max-Allocation)
A B C D
P0 0 4 1 3
P1 0 2 5 2
P2 1 0 0 0
P3 0 1 2 1
P4 0 3 4 1

For Safe Sequence, select a process such that Need of the process < Available
resources.
Current Available Resources= (1, 3, 2, 2)

1st Iteration:
Need (Process P2) = (1,0,0,0) < (1,3,2,2) Available resources
Process P2 completes and returns allocated resources, so
Current Available Resources = (1, 3, 2, 2)
+ Resources Allocated to P2 = (1 ,0, 5,2)
=Current Available Resources= (2, 3, 7, 4)

2nd Iteration:
Need (Process P1) = (0,2,5,2) < (2,3,7,4) Available resources
Process P0 completes and returns allocated resources, so
Current Available Resources = (2, 3, 7, 4)
+ Resources Allocated to P1 = (1, 0, 0, 0)
=Current Available Resources= (3, 3, 7, 4)
3rd Iteration:
Need (Process P3) = (0,1,2,1) < (3,3,7,4) Available resources
Process P1 completes and returns allocated resources, so
Current Available Resources = (3, 3, 7, 4)
+ Resources Allocated to P3 = (0,1, 3, 1)
=Current Available Resources= (3, 4, 10, 5)

4th Iteration:
Need (Process P0) = (0,4,1,3) < (3,4,10,5) Available resources
Process P3 completes and returns allocated resources, so
Current Available Resources = (3, 4, 10, 5)
+ Resources Allocated to P0 = (0, 1, 0, 0)
=Current Available Resources= (3, 5, 10, 5)

5th Iteration:
Need (Process P4) = (0,3,4,1) < (3,5,10,5) Available resources
Process P3 completes and returns allocated resources, so
Current Available Resources = (3, 5, 10, 5)
+ Resources Allocated to P4 = (0, 0, 1, 2)
=Current Available Resources= (3, 5, 11, 7)

so now
Current Available Resources (3, 5, 11, 7)=Total available recourses: (3, 5, 11, 7)
Safe sequence: P2->P1->P3->P0->P4

Q # 3 (a): Find average waiting time using Shortest Job Remaining Time
Method.
Process Arrival Time Burst Time
P1 0.0 7
P2 2.0 4
P3 4.0 1
P4 5.0 4

SJRF using No-Preemption:


Gantt Chart:

P1 P3 P2 P4
0 7 8 12 16

Process Arrival Time Burst Time Finish Time Waiting Time


P1 0.0 7 7 0
P2 2.0 4 12 6
P3 4.0 1 8 3
P4 5.0 4 16 7

Here, waiting time= Finish Time- Burst Time- Arrival Time


Average Waiting Time = 0+6+3+7 /4
=4
SJRF using Preemption:
Gantt Chart:

P1 P2 P3 P2 P4 P1
0 2 4 5 7 11 16

Process Arrival Time Burst Time Finish Time Waiting Time


P1 0.0 7 16 9
P2 2.0 4 7 1
P3 4.0 1 5 0
P4 5.0 4 11 2

Here, waiting time= Finish Time- Burst Time- Arrival Time


Average Waiting Time = 9+1+0+2 /4
=3

Q # 3 (c): Given memory partitions of 100K, 600K, 200K, 300K and 500K (in
order), how would each of the First-fit, Best-fit and Worst-fit algorithms place
processes of 409K, 236K, 125K and 514 K (in order)?
Which algorithm makes the most efficient use of memory?

First-Fit:
409K is put in 600K partition
236K is put in 300K partition
125K is put in 200K partition
514K must wait until a suitable partition is free to use

Best-Fit:
409K is put in 500K partition
236K is put in 300K partition
125K is put in 200K partition
514K is put in 600K partition

Worst-Fit:
409K is put in 600K partition
239K is put in 500K partition
125K is put in 300K partition
514K must wait until a suitable partition is free to use

Best-Fit algorithm is the most suitable and efficient in terms of memory, as the
internal fragmentation is minimum. All memory areas or holes are searched to find
the hole big enough to hold a process. In the above question, only Best-Fit allows all
four processes to execute simultaneously by allocating the holes efficiently.

You might also like