0% found this document useful (0 votes)
26 views10 pages

Final OS Solution

The document outlines the final term exam for Operating Systems (CS2006) at the National University of Computer and Emerging Sciences, detailing the exam date, duration, total marks, and questions. It includes specific questions on topics such as virtual memory, process synchronization, CPU scheduling, threading, and memory management. Each question is broken down into parts with allocated marks and instructions for students to follow during the exam.

Uploaded by

mala ahmad
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)
26 views10 pages

Final OS Solution

The document outlines the final term exam for Operating Systems (CS2006) at the National University of Computer and Emerging Sciences, detailing the exam date, duration, total marks, and questions. It includes specific questions on topics such as virtual memory, process synchronization, CPU scheduling, threading, and memory management. Each question is broken down into parts with allocated marks and instructions for students to follow during the exam.

Uploaded by

mala ahmad
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/ 10

National University of Computer and Emerging Sciences

Chiniot-Faisalabad Campus

Operating Systems (CS2006) Final Term Exam


Date: May 31th 2024 Total Time (Hrs): 3
Course Instructor(s) Total Marks: 100
Mr. Shahbaz Ayyaz, Ms. Mahzaib Younas, Total Questions: 4
Ms. Sahar Ajmal, Ms. Nasreen Akthar.

___________ __________ _____________________


Roll No Section Student Signature

Vetted by: Signature: .

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

Instructions: Solve all the questions on answer booklet.


Must attached your question Paper with answer booklet.
Attempt all the questions.

CLO 4: Deploy OS tools related to Virtualization and Containers

Q1: Virtual Memory [10 + 4 + 8 = 22 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.

Spring 2024 Department of Computer Science Page 1 of 5


National University of Computer and Emerging Sciences
Chiniot-Faisalabad Campus

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:

Swapin pagesize=swapout page size=3MB

Swapin time=swapout time=3*2000=6000ns.MB

EAT=(1-p)*Memory access time+p(PFO+Swapin+Swapout)

=(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

Spring 2024 Department of Computer Science Page 2 of 5


National University of Computer and Emerging Sciences
Chiniot-Faisalabad Campus

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]

Processes Priority Brust Time


P1 2 6
P2 1 4
P3 3 8
P4 2 5
P5 1 7

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.

i. Draw a Gantt chart that illustrates the execution of these processes.


ii. What is the waiting time and turnaround time for each process for the scheduling algorithm

Process Waiting Time Turnaround Time


Process 1
Process 2
Process 3
Process 4
Process 5
iii. Calculate the average waiting and turnaround Time.

Spring 2024 Department of Computer Science Page 3 of 5


National University of Computer and Emerging Sciences
Chiniot-Faisalabad Campus

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)

Spring 2024 Department of Computer Science Page 4 of 5


National University of Computer and Emerging Sciences
Chiniot-Faisalabad Campus

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

Part D: Answer the following Questions [12 Marks]


1. Discuss the contented and uncontended lock. Also discuss the types of contented lock.[4
Marks]
Contended A lock is considered contended if a thread blocks while trying to acquire the lock.
Uncontended If a lock is available when a thread attempts to acquire it, the lock is considered
uncontended
Contended locks can experience either high contention (a relatively large number of threads
attempting to acquire the lock) or low contention (a relatively small number of threads attempting
to acquire the lock.)

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.

Spring 2024 Department of Computer Science Page 5 of 5


National University of Computer and Emerging Sciences
Chiniot-Faisalabad Campus

CLO 2: Implement solutions employing concepts of Processes and Threads


Q3: Threading [4+ 4+ 8 = 16 marks]

Part A: Differentiate between asynchronous and deferred thread cancellation. [4 Marks]


Asynchronous cancellation: One thread immediately terminates the target thread.
Deferred cancellation: The target thread periodically checks whether it should terminate, allowing
it an opportunity to terminate itself in an orderly fashion.

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

Spring 2024 Department of Computer Science Page 6 of 5


National University of Computer and Emerging Sciences
Chiniot-Faisalabad Campus

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].

The average value generated at root node is 52.52 which is wrong:


Reason: This task assign task was to solve the problem using data parallelism which will always
generates wrong result. For correct result you need to implement task parallelism

CLO 5: Understand the dead locks and memory management


Q4: Memory Management and Deadlocks [8 + 4+ 14 + 6 = 32 marks]

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

Spring 2024 Department of Computer Science Page 7 of 5


National University of Computer and Emerging Sciences
Chiniot-Faisalabad Campus

MB, and 185 MB.


4. 75 MB is placed in the 85 MB partition, leaving 10 MB, 170 MB, 40 MB, 5 MB, 115 MB,
and 185 MB.
5. 175 MB is placed in the 185 MB partition, leaving 10 MB, 170 MB, 40 MB, 5 MB, 115
MB, and 10 MB.
6. 80 MB is placed in the 170 MB partition, leaving 10 MB, 90 MB, 40 MB, 5 MB, 115 MB,
and 10 MB.

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]

Spring 2024 Department of Computer Science Page 8 of 5


National University of Computer and Emerging Sciences
Chiniot-Faisalabad Campus

[Note: Don’t Change the data during execution otherwise you will get zero score.]

Proces Allocated Available


Max-Need Remaining need
s Resources resources
A B C D A B C D A B C D A B C D
P0 9 6 6 3 3 3 3 1 6 3 3 2 4 2 5 1
P1 15 6 7 5 2 5 2 1 13 1 5 4 18 12 19 12
P2 14 5 6 1 1 3 1 0 13 2 6 4 20 17 21 13
P3 4 3 5 3 2 1 2 0 2 2 3 3 10 7 13 6
P4 8 7 6 9 5 3 1 3 3 4 5 6 12 8 15 6
P5 3 2 8 5 3 2 5 4 0 0 3 1 7 4 10 5
P6 9 6 9 9 1 1 3 3 8 5 6 6 17 11 16 13
21 20 22 13
i. Find remaining need [3 Marks]
ii. Find total number of resources of each type. [2 Marks]
A=21 B=20 C=22 D=13
iii. Find whether the system is in safe state or not if yes find the safe sequence using all
computation
[6 Marks]
The system has safe sequence and the safe sequence is p5,p0,p3,p4,p6,p1,p2
iv. If the system has safe sequence write that sequence else mentioned where the system stuck to
allocate resources and identify the reasons. [3 Marks]
The system has safe sequence and the safe sequence is p5,p0,p3,p4,p6,p1,p2

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

Spring 2024 Department of Computer Science Page 10 of 5

You might also like