Ass 3

You might also like

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 20

____________________________________________________________________________

QUESTION NO 1:
Suppose we have 64bit logical address with 8KB of page size and size of each entry in the page is 4
Bytes. Calculate the following:
1. Inner page size.
2. Outer page size.
3. Page offset

____________________________________________________________________________
Pg : 01
____________________________________________________________________________

____________________________________________________________________________
Pg : 02
___________________________________________________________________________________

Question 2
Given the following stream of page references by an application, calculate the number of page faults the
application would incur with the FIFO, LRU and Optimal page replacement algorithms. Assume that
there are 3 frames, and all are initially empty. Reference Stream: E D H B D E D A E B E D E B G.

____________________________________________________________________________
Pg : 03
____________________________________________________________________________

____________________________________________________________________________
Pg : 04
____________________________________________________________________________

QUESTION NO 3:

a)Consider the following data of a system has five processes (P0, P1, P2, P3 and P4) and four types of
resources (A, B, C and D). There are multiple resources of each type. Is the following state safe or not? If
it is, show how the processes can complete. If not, show how they can deadlock.

b) Draw the resource-allocation graph when the sets Process, Resource, and Edges are: P = {T1, T2, T3, T4}
         
R = {A, B, C, D} E = {T1 B, A T1, A T2, B T2, T3 B, C T3, T2 C, 4T,CD T3 and D T4}
Assume there exists two instances of resource A and D one instance of resource B and C. As well, assume
resources A, B, C and D are non-preemptive and cannot be shared. (i) Draw wait-for-graph with the help of
resource allocation graph. (ii) Could a deadlock exist in the system? Briefly explain.

____________________________________________________________________________
Pg : 05
____________________________________________________________________________

____________________________________________________________________________
Pg : 06
____________________________________________________________________________

____________________________________________________________________________
Pg : 07
____________________________________________________________________________

____________________________________________________________________________
Pg : 08
____________________________________________________________________________

QUESTION NO 4:

____________________________________________________________________________
Pg : 09
____________________________________________________________________________

QUESTION NO 5:

This problem was originally based on the Senate bus at Wellesley College. Riders come to a bus stop
and wait for a bus. When the bus arrives, all the waiting riders invoke boardBus, but anyone who arrives
while the bus is boarding must wait for the next bus. The capacity of the bus is 50 people; if there are
more than 50 people waiting, some will have to wait for the next bus. When all the waiting riders have
boarded, the bus can invoke depart. If the bus arrives when there are no riders, it should depart
immediately. Write synchronization code using Semaphore.

Answer:
Here are the variables I used in my solution: Bus problem hint
riders = 0
mutex = Semaphore (1)
multiplex = Semaphore (50)
bus = Semaphore (0)
allAboard = Semaphore (0)
mutex protects riders, which keeps track of how many riders are waiting; multiplex makes sure there are
no more than 50 riders in the boarding area. Riders wait on bus, which gets signaled when the bus
arrives. The bus waits on allAboard, which gets signaled by the last student to board.

Bus problem solution #1


Here is the code for the bus. Again, we are using the “Pass the baton” pattern. mutex .

____________________________________________________________________________
Pg : 10
____________________________________________________________________________

wait ()
if riders > 0:
bus . signal () # and pass the mutex
allAboard . wait () # and get the mutex back
mutex . signal ()
depart ()
When the bus arrives, it gets mutex, which prevents late arrivals from entering the boarding area. If
there are no riders, it departs immediately. Otherwise, it signals bus and waits for the riders to board.
Here is the code for the riders:
multiplex . wait ()
mutex . wait ()
riders += 1
mutex . signal ()
bus . wait () # and get the mutex
multiplex . signal ()
boardBus () riders -= 1
if riders == 0:
allAboard . signal ()
else :
bus . signal () # and pass the mutex .
The multiplex controls the number of riders in the waiting area, although strictly speaking, a rider doesn’t
enter the waiting area until she increments riders. Riders wait on bus until the bus arrives. When a rider wakes
up, it is understood that she has the mutex. After boarding, each rider decrements riders. If there are more
riders waiting, the boarding rider signals bus and pass the mutex to the next rider. The last rider signals
allAboard and passes the mutex back to the bus. Finally, the bus releases the mutex and departs.

____________________________________________________________________________
Pg : 11
____________________________________________________________________________

Bus problem solution #2


Grant Hutchins came up with this solution, which uses fewer variables than the previous one, and
doesn’t involve passing around any mutexes. Here are the variables:
waiting = 0
mutex = new Semaphore (1)
bus = new Semaphore (0)
boarded = new Semaphore (0) .
waiting is the number of riders in the boarding area, which is protected by mutex. bus signals when
the bus has arrived; boarded signals that a rider has boarded. Here is the code for the bus.

____________________________________________________________________________
Pg : 12
____________________________________________________________________________

mutex . wait ()
n = min ( waiting , 50)
for i in range (n ):
bus . signal ()
boarded . wait ()
waiting = max ( waiting -50 , 0)
mutex . signal ()
depart ()
The bus gets the mutex and holds it throughout the boarding process. The loop signals each rider in turn and
waits for her to board. By controlling the number of signals, the bus prevents more than 50 riders from
boarding. When all the riders have boarded, the bus updates waiting, which is an example of the “I’ll do it
for you” pattern. The code for the riders uses two simple patterns: a mutex and a rendezvous.
mutex . wait ()
waiting += 1
mutex . signal ()
bus . wait ()
board ()
boarded . signal ().

QUESTION NO 6:

A disk system has 250 cylinders, numbered 300 to 550. Assume that the read / write head is at cylinder 400
and determine the order of head movement for each algorithm to satisfy the following stream of requests.
For comparison purposes, calculate the total head travel distance. They are listed in the order received. 450,
510, 345, 410, 545, 330, 495, 395, 475, 380, 529, 251, 365 Discuss the following algorithms and briefly
explain which algorithm is best. (i) LOOK, (ii) SSTF, (iii) C-SCAN, (iv) FCFS.

____________________________________________________________________________
Pg : 13
____________________________________________________________________________

____________________________________________________________________________
Pg : 14
____________________________________________________________________________

____________________________________________________________________________
Pg : 15
____________________________________________________________________________

____________________________________________________________________________
Pg : 16
____________________________________________________________________________

____________________________________________________________________________
Pg : 17
____________________________________________________________________________

____________________________________________________________________________
Pg : 18
____________________________________________________________________________

QUESTION NO 8:
1) FALSE

2) TRUE

3) FALSE

4) TRUE

QUESTION NO 9:

1) Most disks do not export their rotational position information to the host. Even if they did, the
time for this in order to reach the scheduler would be subject to imprecision and the time
consumed by the scheduler is variable, so the rotational position in order would become
incorrect. Further, the disk requests are usually given in terms of logical block numbers, and the
mapping among logical blocks and physical locations is very difficult.
2) In case of system crash (memory failure) the free-space list would not be lost as it would be if
the bit map had been stored in main memory.
3) There are three main particular files are best which are as follows:
• Contiguous—if file is usually accessed sequentially, if file is relatively small.
• Linked—if file is large and usually accessed sequentially.
• Indexed—if file is large and usually accessed randomly.
4) A file allocation table (FAT) is a file system developed for hard drives that originally used 12 or
16 bits for each cluster entry into the file allocation table. It is used by the operating system
(OS) to manage files on hard drives and other computer systems. It is often also found on in
flash memory, digital cameras and portable devices. It is used to store file information and
extend the life of a hard drive.

____________________________________________________________________________
Pg : 19
____________________________________________________________________________

Deadlock Prevention:
Deadlock prevention means to block at least one of the four conditions required for deadlock to occur.
If we are able to block any one of them then deadlock can be prevented.

The four conditions which need to be blocked are: -


• Mutual Exclusion

• Hold and Wait

• No Preemption

• Circular Wait

Deadlock Avoidance:
In Deadlock avoidance we have to anticipate deadlock before it really occurs and ensure that the
system does not go in unsafe state. It is possible to avoid deadlock if resources are allocated carefully.
For deadlock avoidance we use Banker’s and Safety algorithm for resource allocation purpose. In
deadlock avoidance the maximum number of resources of each type that will be needed are stated at the
beginning of the process.

____________________________________________________________________________
Pg : 20

You might also like