Final OS Solution
Final OS Solution
Chiniot-Faisalabad Campus
CLO No 4 3 2 Total
Question No 1 2 3 4
Total Marks 22 30 16 32
A B C A B C D A B C A B C D 100
Question
Parts
Obtained
Marks
Part A: Consider a computer system with the following sequence of page references:
[5+5 = 10 Marks]
1,3,0,3,5,6,3,1,6,3
The system uses the Least Recently Used (LRU) page replacement algorithm and has 3-page
frames available.
i. Show the contents of the page frames after each page reference in the sequence.
ii. Calculate the total number of page faults that occur.
Part B: Consider a system that uses paging with a fixed page size of 3MB. When the CPU requests a new
page, Px, which is 3MB in size, and the memory is nearly full, the pager will swap out an existing page to load
Px into RAM. Calculate the Effective Access Time (EAT), where [4
Marks]
1. Memory access time is 4 nanoseconds,
2. Page Fault rate is 0.65 nanoseconds.
3. Data transfer rate from back storage to rate or ram to back storage is 2000 nanoseconds per MB
Solution:
=(1-0.65)*4+0.65(PFO+6000+6000)
=1.4+O.65PFO+4200
=4201.4+0.65PFO
Part C: Consider a system that uses paging with a fixed page size of 5MB. When the CPU requests a new
page, Py, which is 2134KB in size, and the memory is nearly full, the pager will swap out an existing page to
load Py into RAM. The page selected for swapping is of size 5MB. [8
Marks]
1. Memory access time is 4 nanoseconds,
2. Page Fault rate is 0.65 nanoseconds. And
3. Data transfer rate from back storage to rate or ram to back storage is 2000 nanoseconds per MB.
Based on scenario given in Part C Answer the following Question:
1) What does the size of Py indicate about its status in the process? [2 Marks]
Answer Py is the last page
2) Compute the Effective access time. [4 Marks]
Swapout=5*2000=10000
Swapin=2134/1024*2000=4167.96
EAT=1.4+0.65pfo+9209.1=9210.4+.65pfo
3) Suppose the process having Py. Page has a total of 21 pages, what will be the total size of process.
[2 Marks]
20*5+2.08=102.08
CLO 3: Evaluate the commonly used mechanisms for scheduling of tasks and implement
synchronization mechanisms like Semaphores, TSL, etc.
Q2: Process synchronization + CPU Scheduling [10 + 5+ 3 + 12 = 30 Marks]
Part A: Consider a computer system with five processes ready for execution. The processes are assumed
to have arrived in the order P1, P2, P3, P4, P5, all at time 0, and a priority assigned to it along with its
burst time: [Note: Must draw the table of Part B in answer Booklet]. [3+5+2 = 10
marks]
Apply the hybrid scheduling model, which combines Priority Queue and round-robin scheduling
algorithms with a time quantum of 2 milliseconds, to schedule the processes for execution. Answer the
following Questions.
Part B: Write down the four circumstances in which CPU schedular can make decision to
choose the next process to be execute. Separately mentioned which circumstances used for
preemptive and non-preemptive schedular. [5
Marks]
This decision can take place at the following times :
1. Switches from running to waiting state; ex: as result of I/O request or wait()
2. Switches from running to ready state; ex: when an interrupt occurs
3 . Switches from waiting to ready at completion of I/O . or because a new process was created
and was placed in the queue .
4 . Terminate
circumstances 1 and 4 is non preemptive
circumstances 2 and 3(running to ready, waiting to ready)
Part C: Consider two concurrently running processes: P1 with a statement S1 and P2 with a
statement S2. Suppose we require that S2 be executed only after S1 has completed. [3
Marks]
We can implement this scheme readily by letting P1 and P2 share a common semaphore synch,
initialized to 0.
• In process P1, we insert the statements • In process P2, we insert the statements •
• P1: P2:
S1; wait(synch);
signal(synch); S2
2. Write down the syntax of binary semaphore for two Processes. Prove that the Binary
semaphore algorithm satisfies all three requirements for the critical-section problem.
[5 marks]
Wait Signal
The wait operation decrements the value of its The signal operation increments the value of
argument S, if it is positive. its argument S.
If S is negative or zero, then no operation is Syntax
performed. Syntax signal(S)
wait(S) { { S++;
while (S<=0); }
3.What
S--; is
} the meaning of the term busy waiting?All What other kinds
modifications of waiting
to the are there in an
integer value
operating system? Can busy waiting be avoided altogether? Explain your answer.
[3 Marks]
Busy waiting means that a process is waiting for a condition to be satisfied in a tight loop without
relinquishing the processor. Alternatively, a process could wait by relinquishing the processor, and
block on a condition and wait to be awakened at some appropriate time in the future. Busy waiting can
be avoided but incurs the overhead associated with putting a process to sleep and having to wake it up
when the appropriate program state is reached.
Part B: Explain the difference between internal and external fragmentation with the help of diagrams.
[4 Marks]
Internal fragmentation
Memory block assigned to process is bigger. Some portion of memory is left unused, as it
cannot be used by another process.
External fragmentation
Total memory space is enough to satisfy a request or to reside a process in it, but it is not
contiguous, so it cannot be used.
Part C: A system with multithreaded environment is using fork and join mechanism to achieve
concurrency. Now the system has following data set: [4+1+3 = 7 Marks]
{ 1 ,50, 45,23,12,80,9,89,76,55,2,77,88,9,67,56,40,7,8,10,0 1}
The task parallelism and data parallelism perform to find the average number among all. Using fork
and join parallelism split the task in diagram. Represent your data in the format {data [split], return
join value(s)}. Split the value till leaf nodes contain 2if odd then 3 values only and then perform back
tracking while computing the average using join operation. Interpret the result at root node and
identify the main cause of this result generated at root node. [Note: it is necessary to Compute
average value for each node].
Part A: Given six memory partitions of 100 MB, 170 MB, 40 MB, 205 MB, 300 MB, and 185
MB (in order), how would the first-fit, best-fit, and worst-fit algorithms place processes of size
200 MB, 15 MB, 185 MB, 75 MB, 175 MB, and 80 MB (in order)? Indicate which—if
any—requests cannot be satisfied. Comment on how efficiently each of the algorithms manages
memory. [8 Marks]
First-Fit Algorithm
1. 200 MB is placed in the 205 MB partition, leaving 100 MB, 170 MB, 40 MB, 5 MB, 300
MB, and 185 MB.
2. 15 MB is placed in the 100 MB partition, leaving 85 MB, 170 MB, 40 MB, 5 MB, 300
MB, and 185 MB.
3. 185 MB is placed in the 300 MB partition, leaving 85 MB, 170 MB, 40 MB, 5 MB, 115
Best-Fit Algorithm
1. 200 MB is placed in the 205 MB partition, leaving 100 MB, 170 MB, 40 MB, 5 MB, 300
MB, and 185 MB.
2. 15 MB is placed in the 40 MB partition, leaving 100 MB, 170 MB, 25 MB, 5 MB, 300
MB, and 185 MB.
3. 185 MB is placed in the 185 MB partition, leaving 100 MB, 170 MB, 25 MB, 5 MB, 115
MB, and 0 MB.
4. 75 MB is placed in the 100 MB partition, leaving 25 MB, 170 MB, 25 MB, 5 MB, 115
MB, and 0 MB.
5. 175 MB is placed in the 300 MB partition, leaving 25 MB, 170 MB, 25 MB, 5 MB, 125
MB, and 0 MB.
6. 80 MB is placed in the 125 MB partition, leaving 25 MB, 170 MB, 25 MB, 5 MB, 45 MB,
and 0 MB.
Worst-Fit Algorithm
1. 200 MB is placed in the 300 MB partition, leaving 100 MB, 170 MB, 40 MB, 5 MB, 100
MB, and 185 MB.
2. 15 MB is placed in the 205 MB partition, leaving 100 MB, 170 MB, 40 MB, 5 MB, 100
MB, and 185 MB.
3. 185 MB is placed in the 190 MB partition, leaving 100 MB, 170 MB, 40 MB, 5 MB, 5
MB, and 185 MB.
4. 75 MB is placed in the 185 MB partition, leaving 100 MB, 170 MB, 40 MB, 5 MB, 5 MB,
and 110 MB.
5. 175 MB cannot be satisfied as there is no partition large enough to hold the request.
6. 80 MB is placed in the 170 MB partition, leaving 100 MB, 90 MB, 40 MB, 5 MB, 5 MB,
and 110 MB.
Part B: Write the steps taken by MMU to translate a logical address generated by the CPU to a
physical address in paging. [4
Marks]
1. Extract the page number p and use it as an index into the page table.
2. Extract the corresponding frame number f from the page table.
3. Replace the page number p in the logical address with the frame number
Part C: Consider the system having multiple instances of each resource type and you are provided
with the resources allocation with the demand and the system reach at the point where each processes
demand for remaining resources. So, the data set is. [14 Marks]
[Note: Don’t Change the data during execution otherwise you will get zero score.]
Part D: Consider the following graph and whether it contains deadlock or not? If not the find the safe
sequences of resource allocation? [6 Marks]
R2
P1 P3
R4
R1
P2 P4
P5
R5
Spring 2024 DepartmentR3of Computer Science Page 9 of 5
National University of Computer and Emerging Sciences
Chiniot-Faisalabad Campus
The above graph doesn’t contain deadlock and the safe sequence is
P5,p3,p1,p2,p4