OS Assignment#3
OS Assignment#3
OS Assignment#3
TECHNOLOGY
INTRODUCTION TO OPERATING SYSTEM
(SWE 204)
ASSIGNMENT # 3
Submitted by :
Muhammad Fahad Siddiqui (2019-SE-206)
Muhammad Ali Hamza (2019-SE-219)
Muhammad Moiz Bakaseer (2019-SE-221)
Shahzaib Ansari (2019-SE-249)
Submitted to :
Miss Falak Saleem
ASSIGNMENT # 3
Question 1 (Solved by 2019-SE-249)
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:
(i) Inner page size.
(ii) Outer page size.
(iii) Page offset
Answer.
Question 2 (Solved by 2019-SE-249)
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.
Answer.
Question 3 (Solved by 2019-SE-249)
(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 = {T1B, AT1, AT2, BT2, T3B, CT3, T2C, T4C, DT3
and DT4}
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.
Answer.
.
Question 4 (Solved by 2019-SE-206)
The following pair of processes share a common set of variables: “counter”, “temp A” and “temp B”
Process A Process B
A1: tempA = counter+1; B1: tempB = counter+2;
A2: counter = tempA; B2: counter = tempB;
The variable “counter” initially has the value 10 before either process begins to execute.
(i) What difference values of “counter” are possible when both processes finished executing? Give
an order of execution of statements from process A and B that would yield each of the values you
give. For example, execution order A1, A2, B1, and B2 would yield the value 13.
(ii) Modify the above programs for processes A and B by adding appropriate signal and wait
operations on the binary semaphore “sync” such that the only possible final value of “counter” is
13. Indicate what should be the initial value of the semaphore “sync”.
Answer.
Question 5 (Solved by 2019-SE-206)
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 board Bus, 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.
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 ().
12
Question 6 (Solved by 2019-SE-206)
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.
Answer.
13
14
15
16
17
Question 7 (Solved by 2019-SE-221)
Consider a file system that uses i-nodes to represent files. Disk blocks are 9-KB in size and a pointer
to a disk block requires 4 bytes. This file system has 12 direct disk blocks, plus single, double, and
triple indirect disk blocks. What is the maximum size of a file that can be stored in this file system?
Answer.
Given data:
Size of the disk block = 9 KB
Size required by the pointer to a disk block = 4 bytes
Now,
Size required by 12 direct disk blocks = 12 × 9
Size required by single disk block = 2048 × 9 KB
Size required by double disk block = 2048 × 2048 × 9 KB
size required by triple disk block = 2048 × 2048 × 2048 × 9 KB
Now,
the maximum size of the file that can be stored in this file system = 12 * 9 + 2048 *9 KB + 2048 * 2048
* 9 KB + 2048 * 2048* 2048 * 9 KB = 81 terabytes
Answer:
81 terabytes.
Answer.
(i)
True
(ii)
False
(iii)
True
(iv)
18
True
Answer.
(i)
Most disks don't export their motility position information to the host. even if they did, the time for
this information to achieve the scheduler would be subject to inexactness and also the time
consumed by the computer hardware is variable, that the motility position info would become
incorrect. Further, the disk requests are sometimes given in terms of logical block numbers, and also
the mapping between logical blocks and physical locations is incredibly complex.
(ii)
In case of system crash (memory failure) the free-space list wouldn't be lost because it would be if
the bit map had been stored in main memory.
(iii)
(iv)
The file system uses associate index table keep on the device to identify chains of information
storage areas related to a file, the File Allocation Table (FAT). The FAT is statically allocated at the
time of information. The table could be a coupled list of entries for every cluster,a contiguous space
of disk storage.
19
(v)
• Deadlock Prevention:
o Preventing deadlocks by constraining how requests for resources can be made in the
system and how they are handled (system design).
o The goal is to ensure that at least one of the necessary conditions for deadlock can
never hold.
• Deadlock Avoidance:
o The system dynamically considers every request and decides whether it is safe to
grant it at this point,
o The system requires additional apriori information regarding the overall potential use
of each resource for each process.
o Allows more concurrency.
Similar to the difference between a traffic light.
20