OS Problems
OS Problems
P2 8-1=7 13
P3 14-2=12 17
P4 19-3=16 26
P2 1-1=0 6
P3 7-2=5 10
P4 19-3=16 26
P2 13-1=12 18
P3 8-2=6 11
P4 19-3=16 26
P2 1-1=0 6
P3 24-2=22 27
P4 14-3=11 21
P2 8-1=7 13
P3 24-2=22 27
P4 14-3=11 21
P2 18-(2x2)=14-1=13 19
P3 20-(2x2)=16-2=14 19
P4 25-(3x2)=19-3=16 26
P1 4 3
P2 2 2
P3 5 1
P4 1 3
Solution:
First Come First Served(FCFS)
Gantt Chart:
P2 1 3
P3 7 12
P4 0 1
P2 5-1=4 6
P3 10-(3x1)=7 12
P4 3 4
Shortest job first scheduling has the lowest waiting and turn-around time
Deadlock-Banker’s Safety and Resourse-request
Algorithm Problem
Consider a system that contains five processes P0,P1, P2, P3, P4 and the three
resource types A, B and C. Following are the resources types: A has 10, B has 5 and
the resource type C has 7 instances.
Allocation Max Available
AB C ABC ABC
P0 010 753 332
P1 200 322
P2 302 902
P3 211 222
P4 002 433
i. Find the need matrix?
ii. Determine if the system is safe or not.
iii. What will happen if the resource request (1, 0, 2) for process P1 can the system
accept this request immediately?
Solution:
i) The Content of the need matrix is as follows:
Need [i] = Max [i] - Allocation [i]
Need
ABC
P0 743
P1 122
P2 600
P3 011
P4 431
ii) Applying Safety algorithm to check whether the system is safe or not
Step1:
Step2:
a. For Segment 0
Check address < length
430 < 600 true
Physical =base + logical address
=219 + 430
=649
b. For Segment 1
Check address < length
10 < 14 true
Physical =base + logical address
=2300+10=2310
c. For Segment 2
Check address < length
500 < 100 false
illegal reference;(traps to OS)
d. For Segment 3
Check address < length
400 < 580 true
Physical =base + logical address
=1327 + 400
=1721
c. For Segment 4
Check address < length
112 < 96 false
illegal reference;(traps to OS)
Page Replacement Algorithm Probem
70120304230321201701
How many page faults would occur for the following algorithms assuming 3
frames
i)FIFO replacement
ii)Optimal replacement
iii)LRU replacement
Solution:
FIFO replacement
Solution:
Effective Access Time(EAT)= P x hit memory time + (1-P) x miss
memory time.
Where: P is Hit ratio
or
EAT= (TLB hit ratio x (TLB access time+ Memory access time))+ (TLB
miss ratio x (TLB access time + 2* Memory access time) )
P=60/100=0.6(TLB hit ratio)
1-P=1-0.6=0.4(TLB miss ratio)
EAT=(0.6 x (10+80))+(0.4 x (10+80+80))=122ns
Disk Scheduling Problem
Consider a disk queue with requests for I/O to blocks on cylinders 98, 183, 37,
122, 14, 124, 65, 67. The head is initially at cylinder number 53. The cylinders are
numbered from 0 to 199. Calculate the total head movement (in number of
cylinders) incurred while servicing these requests is using FCFS , SSTF , SCAN ,
C-SCAN , C-LOOK scheduling algorithms
Solution:
First Come First Served(FCFS)