0% found this document useful (0 votes)
2 views34 pages

OS Problems

The document discusses various CPU scheduling algorithms including FCFS, SJF (both preemptive and non-preemptive), Priority (both preemptive and non-preemptive), and Round Robin, providing Gantt charts and calculations for average waiting and turnaround times for given processes. It also covers deadlock detection using the Banker's algorithm, dynamic storage allocation strategies, segmentation problems, page replacement algorithms, effective access time calculations, and disk scheduling methods with total head movement calculations. Each section compares the efficiency of the algorithms and provides solutions to specific problems related to resource management and scheduling.

Uploaded by

meghamex2k5
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views34 pages

OS Problems

The document discusses various CPU scheduling algorithms including FCFS, SJF (both preemptive and non-preemptive), Priority (both preemptive and non-preemptive), and Round Robin, providing Gantt charts and calculations for average waiting and turnaround times for given processes. It also covers deadlock detection using the Banker's algorithm, dynamic storage allocation strategies, segmentation problems, page replacement algorithms, effective access time calculations, and disk scheduling methods with total head movement calculations. Each section compares the efficiency of the algorithms and provides solutions to specific problems related to resource management and scheduling.

Uploaded by

meghamex2k5
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 34

CPU Scheduling Problems

1. Explain FCFS, SJF(Preemptive and non-preemptive), Priority(preemptive and


non-preemptive) and Round robin (time slice=2) scheduling algorithms with Gantt
chart for the four processes given. Compare their average waiting and turnaround
time and find which algorithm takes less time.
Process Arrival Time Burst Time Priority
P1 0 8 2
P2 1 6 1
P3 2 5 3
P4 3 10 2
Solution:
First Come First Served(FCFS)
Gantt Chart:

Process Waiting Time Turn around time


(waiting time-arrival time) (burst time +waiting time)
P1 0-0=0 8

P2 8-1=7 13

P3 14-2=12 17

P4 19-3=16 26

Average waiting time =(0+7+12+16)/4=35/4=8.75ms


Average turn-around time=(8+13+17+26)/4=64/4=16ms
Shortest Job First(SJF)-Preemptive
or
Shortest Remaining Time First(SRTF)
Gantt Chart:

Process Waiting Time Turn around time


(waiting time-arrival time) (burst time +waiting time)
P1 12-1=11-0=11 19

P2 1-1=0 6

P3 7-2=5 10

P4 19-3=16 26

Average waiting time = (11+0+5+16)/4 = 32/4 = 8ms


Average turn-around time=(19+6+10+26)/4=61/4=15.25ms
Shortest Job First(SJF) - Non-Preemptive
Gantt Chart:

Process Waiting Time Turn around time


(waiting time-arrival time) (burst time +waiting time)
P1 0-0=0 8

P2 13-1=12 18

P3 8-2=6 11

P4 19-3=16 26

Average waiting time = (0+12+6+16)/4 = 34/4 = 8.5ms


Average turn-around time=(8+18+11+26)/4 = 63/4 =15.75ms
Priority (Preemptive)
Gantt chart:

Process Waiting Time Turn around time


(waiting time-arrival time) (burst time +waiting time)
P1 7-1=6-0=6 14

P2 1-1=0 6

P3 24-2=22 27

P4 14-3=11 21

Average waiting time = (6+0+22+11)/4 = 39/4 = 9.75ms


Average turn-around time=(14+6+27+21)/4 = 68/4 =17ms
Priority (Non-Preemptive)
Gantt chart:

Process Waiting Time Turn around time


(waiting time-arrival time) (burst time +waiting time)
P1 0-0=0 8

P2 8-1=7 13

P3 24-2=22 27

P4 14-3=11 21

Average waiting time = (0+7+22+11)/4 = 40/4 = 10ms


Average turn-around time=(8+13+27+21)/4 = 69/4 =17.25ms
Round Robin
Gantt chart:

Process Waiting Time Turn around time


(waiting time-arrival time) (burst time +waiting time)
P1 23-(3x2)=17-0=17 25

P2 18-(2x2)=14-1=13 19

P3 20-(2x2)=16-2=14 19

P4 25-(3x2)=19-3=16 26

Average waiting time = (17+13+14+16)/4 = 60/4 = 15ms


Average turn-around time=(25+19+19+26)/4 = 89/4 =22.25ms
Shortest job first preemptive scheduling or Shortest remaining time first has
the lowest waiting and turn-around time
2. Explain FCFS, SJF, Priority and Round robin (time quantum=1ms)
scheduling algorithms with Gantt chart for the four processes given. Compare
their average waiting and turnaround time and find which algorithm takes less
time.

Process Burst Time Priority

P1 4 3

P2 2 2

P3 5 1

P4 1 3
Solution:
First Come First Served(FCFS)
Gantt Chart:

Process Waiting Time Turn around time


(burst time +waiting time)
P1 0 4
P2 4 6
P3 6 11
P4 11 12

Average waiting time = (0+4+6+11)/4 = 21/4 = 5.25ms


Average turn-around time=(4+6+11+12)/4 = 33/4 = 8.25ms
Shortest Job First(SJF)
Gantt Chart:

Process Waiting Time Turn around time


(burst time +waiting time)
P1 3 7

P2 1 3

P3 7 12

P4 0 1

Average waiting time = (3+1+7+0)/4 = 11/4 = 2.75ms


Average turn-around time=(7+3+12+1)/4 = 23/4 = 5.75ms
Priority
Gantt chart:

Process Waiting Time Turn around time


(burst time +waiting time)
P1 7 11
P2 5 7
P3 0 5
P4 11 12

Average waiting time = (7+5+0+11)/4 = 22/4 = 5.5ms


Average turn-around time=(11+7+5+12)/4 = 35/4 = 8.75ms
Round Robin
Gantt chart:

Process Waiting Time Turn around time


(burst time +waiting time)
P1 9-(3x1)=6 10

P2 5-1=4 6

P3 10-(3x1)=7 12

P4 3 4

Average waiting time = (6+4+7+3)/4 = 20/4 = 5ms


Average turn-around time=(10+6+12+4)/4 = 32/4 = 8ms

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 for P0: (7, 5, 3) - (0, 1, 0) = 7, 4, 3


Need for P1: (3, 2, 2) - (2, 0, 0) = 1, 2, 2
Need for P2: (9, 0, 2) - (3, 0, 2) = 6, 0, 0
Need for P3: (2, 2, 2) - (2, 1, 1) = 0, 1, 1
Need for P4: (4, 3, 3) - (0, 0, 2) = 4, 3, 1

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:

The system is in a safe state since the sequence


< P1, P3, P4, P2, P0> satisfies safety criteria.
ii) P1 requests (1,0,2) we have to check whether this request can be granted or
not by applying Resource-request algorithm

Step 6: We arrive at the following


The request for P1
can be granted
new state
Step 7: Applying safe state algorithm

The new system state is safe and the safe sequence


is <P1,P3,P4,P0,P2>
Dynamic Storage Allocation Problem
Given memory partitions of 100KB , 500KB , 200KB,300KB,600KB(in order)
how would each of the first-fit , best-fit , worst-fit algorithms place processes
of 212KB , 417KB , 112KB , 426KB(inorder)? Which algorithm makes the
most efficient use of memory?
Solution:
First Fit (Allocates the first hole that is big enough)
Best Fit ( Allocates the smallest hole that is big enough )
Worst Fit ( Allocates the largest hole )
Segmentation Problem

Consider the following segment table


Segment Base Length
0 219 600
1 2300 14
2 90 100
3 1327 580
4 1952 96

What are the physical addresses for the logical addresses?


0430
110
2500
3400
4112
Solution:
Given logical address

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

Consider the following page-reference string

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

The number of page faults =15


Optimal replacement

The number of page faults = 9


LRU replacement

The number of page faults =12


Effective Access Time

In a paging system, it takes 10 ns to search TLB and 80 ns to access


main memory. If TLB hit ratio is 60%.Calculate the effective
memory access time.

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)

Total head movement = (98-53)+(183-98)+(183-37)+(122-37)+


(122-14)+(124-65)+(67-65)
= 640 cylinders
Shortest-Seek-Time-First(SSTF)

Total head movement = (65-53)+(67-65)+(67-37)+(37-14)+


(98-14)+(122-98)+(124-122)+(183-124)
= 236 cylinders
SCAN or Elevator algorithm

Total head movement = (53-37)+(37-14)+(14-0)+(65-0)+


(67-65)+(98-67)+(122-98)+(124-122)+(183-124)
= 236 cylinders
C-SCAN

Total head movement = (65-53)+ (67-65)+(98-67)+(122-98)+(124-122)+(183-


124) +(199-183)+(199-0)+(14-0)+(37-14)
= 382 cylinders
C-LOOK

Total head movement = (65-53)+ (67-65)+(98-67)+(122-98)+(124-122)+(183-


124)+(183-14)+(37-14)
= 322 cylinders
Suppose that the disk rotates at 7200 rpm. What is the rotational
latency of the disk drive?
Solution:
Convert disc rotation to seconds = 7200/60 =120
Single rotation = 1/120 = 0.00833 x 1000 = 8.33 msec
Rotational latency = ½ x single rotation = ½ x 8.33
= 4.17msec

You might also like