You are on page 1of 19

COMPE-431 OPERATING SYSTEMS

SAMPLE QUESTIONS:

1. Compare The Shortest Job First algorithm of processor scheduling with a


Longest Job First algorithm. Give an example to compare processor
utilization, turnaround time and throughput.
2. Assume that the Ready Queue has the following jobs in the given order.

Job CPU Burst (msec) Priority


P1 6 3
P2 1 1
P3 2 3
P4 1 4
P5 3 2

There is no I/O requirement for any of the jobs.


a) Calculate the turnaround-time of each job using First Come First Served,
Shortest Job First, Round Robin(q=1) and non-preemptive priority
scheduling? Assume that context switching overhead is 1 msec. for saving
and another 1 msec. for loading registers of a process.
b) Calculate the waiting time for each job with each of the 4 scheduling
algorithms given above. Use the same assumptions.

3. Given the following process data for a Round-Robin Scheduling algorithm


where q=5. If two processes enter to the ready queue at the same time, then
they will enter in the alphabetical order of their names.

Process Arrival CPU I/O CPU


P1 0 4 5 6
P2 3 3 - -
P3 10 2 7 7

a) Draw the Gantt chart by assuming a 0 context switching time. What is the
average waiting time and CPU utilization?
b) Assume that the context switching time is 1, repeat a).
c) Briefly discuss how the time slice should be selected to increase the
performance of the system given average CPU burst time, average I/O and
context switching time.

4. The following arrival and CPU times are given..

Job CPU Burst Arrival


P1 7 0
P2 4 2
P3 1 3
P4 6 6
a) For Shortest Job First algorithm, draw the Gantt chart and calculate the
average waiting time.
b) Repeat a) for the Shortest Remaining Time First method.
c) Explain the main difference between these two methods.

5. Explain briefly:
a) What is an I/O bound job?
b) What is a CPU bound job?
c) Suppose there is one I/O bound job and one CPU bound job in a ready
queue. Which one should get the processor in order to achieve a better
CPU utilization?
d) Repeat c) for a better I/O device utilization.

6. If there are n processes to be scheduled on m processors, how many different


schedules are there? Give a formula in terms of n and m.
7. Explain briefly:
a) Long-term scheduler
b) Short-term scheduler

Which one is used to control the degree of multiprogramming?

8.
a) Draw the Gantt chart for the given data. Use a preemptive shortest
remaining time first algorithm. Indicate clearly every preemption times.

Job CPU Burst Arrival


P1 12 0
P2 9 2
P3 2 5
P4 7 5
P5 3 9
P6 1 10

b) Calculate the turnaround times for each process and give the average.

9. Consider a priority based scheduling algorithm in which priorities are


computed as the ratio of processor execution time to real time(total elapsed
time)
a) Discuss whether CPU bound or I/O bound processes get higher priority.
Explain.
b) Assume that priorities are calculated every second. Assume there is no
I/O. To which algorithm does this algorithm converge?
10. Draw the Gantt chart using the table given. Draw CPU and I/O charts and use
Shortest Job First algorithm for the CPU. Assume First Come First Serve
algorithm is used for I/O queues. What is the average waiting time in the ready
queue?

Process Arrival CPU-1 I/O-1 CPU-2 I/O-2 CPU-3


P1 0 4 4 4 4 4
P2 2 6 2 6 2 -
P3 3 2 1 2 1 -
P4 7 1 1 1 1 1

11. Draw the Gantt chart for CPU and I/O queues using the given table. Shortest
Remaining Time First method is used for CPU. Find average waiting time in
the ready queue. Assume FIFO is applied to the I/O queue.

If the processes enter to the ready queue at the same time because of a)
preemption, b) new submission, or c) completion of I/O, then the process of case
a) will be in front of the process in case b) which will be in front of the process of
case c)

Process Arrival CPU-1 I/O-1 CPU-2 I/O-2 CPU-3


P1 0 4 4 4 4 4
P2 2 8 1 8 1 -
P3 3 1 1 1 1 -

12. Consider a priority based processor scheduling algorithm such that whenever
there is a process in the ready queue having priority higher priority than the
one executing in CPU, it will force the executing process to preempt the CPU,
and itself will grab the CPU. If there are more then one such processes having
highest priority, then among these the one that entered into the ready queue
first should be chosen. Assume that all the processes have a single CPU burst
and have no I/O operation and consider the following table:

Process Pi Submit(i) msec Burst(i) msec


P1 12 0
P2 9 2
P3 2 5

where Submit(i) denotes when process Pi is submitted into the system


(assume they are submitted just before the tic of the clock) and Burst(i)
denotes the length of the CPU burst for process Pi . Let Tnow to denote the
present time and Execute (i) to denote the total execution of process Pi in
CPU until Tnow. Assuming that the priorities are calculated every msec. (just
after the tic of the clock), draw the corresponding Gantt charts for the following
priority formulas, which are valid when the process has been submitted but not
terminated yet,
a) Priority(i) = Tnow – Submit(i)
b) Priority(i) = Burst(i) – Execute(i)
c) Priority(i) = 1 / (Burst(i) – Execute(i) )

13. Use the data given. Context switching is negligible. There is a single I/O
device using FIFO method. Draw Gantt chart for CPU and I/O device.
Calculate average turnaround time and CPU utilization for

a) First Come First Serve


b) Round Robin (q=2)

Process Arrival CPU-1 I/O-1 CPU-2


P1 0 2 4 4
P2 1 1 5 2
P3 8 2 1 3

14. Use the given data.

Process Arrival CPU


P1 0 7
P2 1 5
P3 2 3
P4 5 1

a) Draw the Gantt chart if non-preemptive Shortest Job First algorithm is


used.
b) Repeat a) if preemptive Shortest Job First is used.
c) Repeat a) if non-preemptive priority based CPU scheduling is used with the
following formula

priority(i) = 10 + tnow – tr(i) – CPU(i)

where

tr(i) = the time where process i enters to the ready queue last time
CPU(i) = next CPU burst for process i.
tnow = current time.

d) For each case above explain if starvation may occur or not.

15. Explain the reasons for a memory management and CPU scheduling
algorithms in a multiuser system? Can we do without them?

16. Explain Internal and external fragmentation.


17. For each memory management method discussed indicate the types of
fragmentation caused.

18. A system is using paging with four associative registers. Use the data given
below for registers and page table:
PT for user_12
Page # Frame #
0 9
1 6
2 15
3 7
4 42

Associative registers
User # Page # Frame #
12 3 7
5 2 18
12 4 42
9 0 10
PTLR(12) = 5
PTBR(12) = 50000
Page Size = 1024 words

For the given logical addresses generated by user_12


o find out the physical addresses
o explain how the addresses are found
o the number of physical memory accesses needed
o If the address is invalid, explain

<2,1256>
<4,572>
<0,14>
<3,290>
<5,290>

19. Given the memory map below with variable partitioning memory management
method.

J1 (50K)

Free (45K)

J2 (40K)

Free (10K)
J3 (20k)
Free (30K)
Jobs arrive/leave in the given order:

J4 (10K) arrives
J5 (20K) arrives
J6 (15K) arrives
J7 (20K) arrives
J3 leaves
J8 (50K) arrives

Draw the memory map after each step of the above job arrivals for the following
methods:
a) First – fit
b) Best – fit
c) Worst - fit

20. Assume a system which uses paging and associative registers


a) Explain the logical to physical address translation
b) What is the effective memory access time where

Assoc. reg. access time = 50 nanosec.


Memory access time = 250 nanosec
Hit ratio = 80%

c) With the data given above calculate the min hit ratio to have an
effective memory access time of 320 nanosec.

21. Consider a system using segmentation also has the ability to share segments.
Segment numbers are fixed. To share segments a shared segment table
(SST) is needed and segment table (ST) must be modified. Assume the
system is capable of dynamic relocation but to reduce overhead it should be
used only when absolutely necessary.
ST-6
Seg # Base Size shares
0 - - 256
1 0 100 -
2 100 90 -
3 600 15 -

ST-9
Seg # Base Size shares
0 190 100 -
1 - - 256
2 290 10 -

SST
Seg # Base Size # of shares
256 400 200 2
Assume maximum number of segments per process is 256, and segments are
numbered starting with 0.
a) What should be done when a segment previously unshared, becomes a
shared segment?
b) When dynamic relocation is needed in this system?
c) Assume segment-2 of process 6 is being executed. A reference is made to
segment-0 of process 6. How is the corresponding physical address going to
be found?
d) How would self-references within shared segments be handled?
e) What is the # of shares field in SST used for?

22. In a computer system, logical addresses are 24 bits long. The machine
implements paged segmentation with a maximum segment size of 64K words
and 4K-word pages:

a) Show in detail the logical address structure. Indicate segment, page and
displacement bits.
b) How many segments can a process have?
c) If a process needs to be loaded fully into memory, what is the minimum
physical memory size?
d) If the physical memory has 65536 frames, show the physical address
structure.
e) Draw a functional block diagram for implementing paged segmentation.
Indicate the sizes of all necessary tables.

23. The following memory map is given. Assume jobs arrive in the given order.

P1

Free (30K)

P2

Free (20K)

P3
Free (50K)
P4

• P5 (16K) arrives
• P6 (40K) arrives
• P7 (20K) arrives
• P8 (14K) arrives
• P5 leaves
• P9 (30K) arrives
a) Draw memory maps after P8 arrives and after P9 arrives, using first-fit,
best-fit and worst-fit allocation methods. Assume there is no compaction.
b) Draw the same memory maps in a) and perform compaction whenever
necessary. Show the map after each compaction as well.

24. In a system that uses paging, the logical address is 20 bits long, where the
most significant 8 bits is the page number; the least 12 bits denote the offset.
Memory size is 256KByte
a) What is the page size (in bits)?
b) What is the maximum number of pages per process?
c) How many frames does the system have?
d) Give the page table structure. Assume 2 bits are used for attributes.
e) How many bits are required for each page table entry?
f) Assume the memory is increased to 1024Kbytes; recalculate c) and e).

25. Consider a system using segmentation where :

STBR = 1000
STLR=5
Associate Registers Access Time = 50nsec
Memory Access Time = 500nsec
ST
Segment # Base Limit
0 10000 1000
1 12000 2000
2 25000 4000
3 15000 8000
4 38000 4000

AR
Segment # Base Limit
0 10000 1000
1 12000 2000

Assume that data can be written into associative registers in parallel with a memory
read or write. To replace data in associative registers LRU policy is used.

For each address, find the physical address and total time spent in calculating that
address. Indicate which memory locations are accessed during address translation.
Show all changes to associative registers.

<0, 150>
<0, 3700>
<2, 900>
<2, 3780>
<5, 200>
<1, 200>
26. Given the memory map below. Apply worst-fit algorithm and draw the final
map. Indicate if compaction is needed.

P1

Free (9K)

P2

Free (20K)

P3
Free (14K)
P4

• P5 (3K)
• P6(5K)
• P7(7K)
• P8(6K)

27. Variable partitioning is used for the memory map. Find the resulting memory
map for the jobs below using first-fit, best-fit and worst-fit algorithms. Indicate if
compaction is needed.

P1(9K)

Free (20K)

P2(11K)

Free (10K)

P3(18K)
Free (30K)

• P5 (3K)
• P6(5K)
• P7(7K)
• P8(6K)
28. A demand paging system is using associative registers
a) Assume the the hit ratio is 80%, register access time is 50nanosec and
memory access time is 950nanosec. Calculate the effective memory
access time (emat). Assume that registers can be loaded in parallel
with an access to the main memory.
b) If the probability of a page fault is 0.005, calculate effective access time
where the page fault service time is 5msec. Use emat calculated
above.
29. In a demand paging system, the working window size is 7. Given the following
reference string for process P:

1, 2, 1, 4, 3, 4, 1, 2, 1, 4, 5, 2, 5, 3, 5, 2, 3
Tnow

a) Calculate the current working set?


b) Calculate the current working set size?
c) What happens if the sum of all working set sizes of currently executing
processes is larger than the total number of frames in the memory?
d) Suggest a method to solve the problem in c).

30. Given the following reference string below for a demand paging system which
uses FIFO page replacement algorithm:

4, 3, 2, 1, 4, 3, 5, 4, 3, 2, 1, 5

a) Assume that there are 3 memory frames. Give a picture of all pages in
memory for the reference string, after each page fault.
b) Repeat a) using 4 memory frames.
c) Comment on the total # of page faults in a) and b).

31. A demand paging system has the following values:

CPU utilization = 30%


Disk utilization = 95%
I/O device utilization = 10%

Discuss one by one if the following changes can improve the processor
utilization:

a) Replace CPU with a slower one.


b) Replace CPU with a faster one.
c) Replace the disk with a faster one.
d) Increase the degree of multiprogramming.
e) Decrease the degree of multiprogramming
f) Replace the I/O device with faster ones.
32. Consider a demand paging system policy: Examine each page regularly, and
swap those pages, which have not been used since the last examination, to
disk. Comment if this policy works better than LRU page replacement policy or
not.
33. Given a demand paging system. The effective memory access time is 8000
nanosec. It takes 9milisec to service a page fault if a free frame is found in
memory, or the page to be replaced is not dirty. It takes 22miliseconds to
service a page fault if there are no free frames and the victim page is dirty. In
7 out of 10 page faults, a victim page has to be chosen and in 5 of these 7
cases, the victim page is dirty. What is the acceptable page fault rate for this
system in order to have an effective access time of 2miliseconds?
34. In a virtual memory system, what determines the size of the logical address
space? What defines the size of the physical address space? What is the
relation between them?
35. Consider LRU page replacement algorithm
a) Explain how it works
b) Why do we need extra hardware such as dirty bit or reference bit in
order to implement LRU algorithm in a demand paging system?
c) Assume there are 4 frames. Give the diagram of all pages in memory
after each page fault for the given reference string:

2, 4, 5, 4, 9, 2, 7, 4, 8, 9, 1, 6, 2, 2, 5, 3, 8
d) In demand paging system, why is it more desirable to replace an
unmodified page rather than a modified one?
e) When is it more desirable to replace a modified page?

36. Assume that we have an n-bit counter associated with each frame in a virtual
memory system with f frames. Assume that demand paging is used. Every
time any page is referenced by a process, a ‘1’ is shifted into the most
significant bit of the counter associated with the referenced page and zeros
are shifted into the counters of all other frames allocated to the referencing
process. The least significant bits are discarded by this operation. The lowest
numbered frame with the lowest counter value is replaced in case of a page
fault.

a) Show the frame contents after each page reference for the following
reference string, where n=2 (2 bit counters) and f=4. Assume initially all
frames are empty with counters=00. There is onşy one process.
Reference string : 4, 3, 4, 7, 2, 3, 5, 8

37. For each case, show the memory contents.


a) Assume a single process
Page reference string: 1, 6, 1, 4, 1, 2, 5, 7, 3
Initial memory content:

Frame No Content
1 4
2 8
3 3
4 5
Use OPT algorithm

b) Assume there are two processes A and B.


Page ref. string: A4, A8, B2, B3, A3, B1, A5, A7, B3, B8, B7, B1, A4, A3

Initial memory content:

Frame No Content
1 A5
2 A2
3 B3
4 B4

Use OPT policy with equal frame allocation


c) Same as b) with global OPT policy
d) Same as b) with local LRU policy
e) For cases b), c) and d), calculate average access time if total of page
swap-in and swap-out time is 40msec, memory access time is 10µsec
and an average of 100 access are made to a page once it is called.

38. Assume a demand paging algorithm with a working window size = 4 (that is
the last 4 page references of each process constitute the windows of those
processes). Assume this working set size correctly reflects program locality
characteristics.

Time: 1 2 3 4 5 6 7 8 9 10 11 12 13 14
Ref: A3 B1 A1 A2 B3 B4 A3 A4 B2 B4 A1 A3 A1 B2

a) What is the working sets for t = 9 and for t=14?


b) Under these conditions and at the time instants at part a), should the
OS increase the multiprogramming degree, or decrease it to improve
CPU utilization? Why? Real memory = 4 frames.
c) Answer b) if real memory is 7 frames.

39. Equal local frame allocation policy is used in a demand paging system. A
process allocates f frames. All these f frames were initially empty. The process
has a page reference string length=s. There are exactly n distinct page
numbers in this string. Consider OPT, LRU, and FIFO algorithms.
a) If n <= f,
1. What is the min # of page faults for this process with this
reference string? Which page replacement algorithm can
achieve this number?
2. What is the max # of page faults for this process with this
reference string? Which algorithm may cause this many page
faults?
b) If n>f, repeat 1. and 2.
40. Consider a demand paging system with 3 frames in memory. Page
replacement policy is LRU, and a global replacement is done. However, it is
given that each process needs at least one page in memory for execution.
There are two processes, P1 and P2 executing in the system. Assume the
following reference string is given.

(1,4,r) (1,4,w) (1,2,r) (1,3,w) (2,1,r) (2,1,w) (2,2,r) (2,3,w) (1,4,r) (1,2,w) (1,3,r) (2,1,w)

where it means :

(i,j,r): i'th process references page j for a read.


(i,j,w): i'th process references page j for a write.

Find and indicate the page faults caused by this string, and after each page fault,
show the page tables for P1 and P2, indicating the values of valid/invalid and the
dirty bits. Assume both processes have 5 pages.

Initially assume that all the 3 frames are empty. Also assume that the processes
have not completed their execution at the end of the given reference string.

Is this system trashing? If yes, what is the minimum number of frames this system
should have to execute this reference string of P1 and P2 efficiently?

41. Consider a computer system which uses demand paging system. Assume the
system also has associative registers to implement the page table. Given :

Associative register access time=100 nanoseconds


Main memory access time = 300 nanoseconds
Hit ratio in associative registers =80%.
Page fault ratio = 0.1%
Page-fault service time= 200 000 nanoseconds

a) What is the total memory access time if there is a hit in associative


registers and no page fault?
b) What is the total memory access time if there is a miss in associative
registers but no page fault?
c) What is the effective memory access time, no page fault?
d) What is the effective access time when page faults are considered?

42. In a system having 4 frames, consider the following page references of


process A and B.

time: 1 2 3 4 5 6 7 8 9 10 11 12
ref: A1 A2 B1 B2 A1 A3 B3 B1 A1 A3 B1 B4

Show the content of memory, and indicate whenever there is a page fault if
a) FIFO algorithm is used with global replacement
b) FIFO algorithm is used with local replacement with equal allocation
c) repeat a. with LRU
d) repeat b. with LRU

43. A working set demand paging algorithm with window size=4 (that is, last 4
page references of each process constitute the windows of those processes)
is to be applied on the reference string

time: 1 2 3 4 5 6 7 8 9 10 11 12
ref: A1 A2 B1 B2 A1 A3 B3 B1 A1 A3 B1 B4

a) write the working sets


i. for t=8, ii. for t=12.
b) if the system has 4 frames, decide on if the system is trashing or not
for
i. t=8, and ii. t=12

44. Consider a computer system having virtual memory with paging. Assume that
the system also has the associative registers. Let:

associative register access time=50 nanosec


memory access time=350 nanosec
hit ratio=90%
swap_in= 100000 msec
swap_out= 200000 msec

a) calculate effective memory access time if no page fault occurs


b) calculate effective access time if page-fault rate=0.001
c) calculate effective access time if dirty bit is used, and the probability for
a page being dirty is %60

45. In a system using working set model for frame allocation, explain what
happens if the window size is chosen
a) smaller than the proper size
b) larger than the proper size

46. For each of the following resource allocation graphs, find out and explain
whether there is a deadlock or not
a)

r1
r2

P1

P3

P2

r3

b)

P4 r3

r1
P1

r4
P2
P3

r2

c)

r1 r2

P2 P3
P1 P4

r4 r3
d)

r1

P2

P3
P1 P4

r3

r2

47. 2. A computer system has m resources of the same type and n processes
share these resources. Prove or disprove the following statement for the
system:

This system is deadlock free if sum of all maximum needs of processes is less
than m+n.

48. There are four processes which are going to share nine tape drives. Their
current and maximum number of allocation numbers are as follows :

process Current maximum


P1 3 6
P2 1 2
P3 4 9
P4 0 2

a) Is the system in a safe state? Why or why not?


b) Is the system deadlocked? Why or why not?
49. Given the following resource allocation diagram,

P3

P1 r1

P2 r3
r2

P4

a) If another instance of resource r1 is made available, is the deadlock


resolved ? If yes specify the allocation sequence, if no explain why?
b) Repeat a) for resource r2.
c) Repeat a) for resource r3.

50. Given that all the resources are identical, they can be acquired and released
strictly one at a time, and no process ever needs more than the total
resources on the system, state whether deadlock can occur in each of the
following systems.

Explain why or how.


Number of Number of
processes resources
a) 1 1
b) 1 2
c) 2 1
d) 2 2
e) 2 3

51.
a) What are the four conditions necessay for deadlock to appear?

b) Cinderella and the Prince are getting divorced. To divide their property,
they have agreed on the following algorithm. Every morning, each of
one may send a letter to the other's lawyer requesting one item of
property. Since it takes a day for letters to be delivered, they have
agreed that if both discover that they have requested the same item on
the same day, the next day they will send a letter cancelling the
request. Among their property is the glass shoe, their dog Woofer,
Woofer's doghouse, their canary Tweeter, Tweeter's cage and a sword.
The animals love their houses, so it has been agreed that any division
of property separating an animal from its house is invalid, requiring the
lawyers to negotiate on which items they already have should be
returned back. Unfortunately the lawyers are stubborn and never agree.
Is deadlock or starvation possible in such a scheme? Explain.

c) What happens if it has been agreed that in the case of any division of
property separating an animal from its house the whole division to start
over from scratch, instead of letting the lawyers to discuss. Explain if
starvation or deadlock possible now.

52. Given the following resource allocation diagram:

P1
P2 P3

r1
r2 r3
P4 r4

P5

a) Apply the deadlock detection algorithm and either indicate why the system is
deadlocked, or specify a safe allocation sequence.
b) If the process P2 also request 2 instances of resource r1, does the system
enter a deadlock? Why?
c) If a deadlock occurs in part a. and/or b., killing which process would resolve
the deadlock?
d) If the maximum declared needs are:
Process r1 r2 r3 r4
P1 4 0 0 0
P2 1 3 1 1
P3 0 0 2 1
P4 1 1 1 0
P5 1 0 1 1

does the current allocation given in part a constitute a safe state? Why?

53. Explain if the system in the figure is dedlocked. If not, give an execution order
of the processes which successfully terminates.

r2

P1 r1
P3

P5
P4

r4

P2
r3

54.
a) Explain if the following system is deadlocked or not?
b) For the following resource allocation graph, for deadlock detection show the
current contents of the AVAILABLE, ALLOCATION, REQUEST .

r1
r2

P1 P2 P3 P4

r3 r4 P5

You might also like