0% found this document useful (0 votes)
43 views

Muzffarpur Institute of Technology, Muzaffapur: Operating System (106503P)

The document discusses operating systems concepts like deadlock, paging, segmentation, and address translation. It defines deadlock as when a set of processes are blocked because each holds a resource and waits for another held by another process. Four conditions must be met for deadlock: mutual exclusion, hold and wait, no preemption, and circular wait. Banker's algorithm is used for deadlock avoidance by simulating resource allocation to ensure the system remains in a safe state. Paging divides memory into fixed-size pages while segmentation uses variable-sized segments. Address translation involves page tables that map virtual to physical addresses, with demand paging loading pages from disk on-demand.

Uploaded by

Abram Jaz
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views

Muzffarpur Institute of Technology, Muzaffapur: Operating System (106503P)

The document discusses operating systems concepts like deadlock, paging, segmentation, and address translation. It defines deadlock as when a set of processes are blocked because each holds a resource and waits for another held by another process. Four conditions must be met for deadlock: mutual exclusion, hold and wait, no preemption, and circular wait. Banker's algorithm is used for deadlock avoidance by simulating resource allocation to ensure the system remains in a safe state. Paging divides memory into fixed-size pages while segmentation uses variable-sized segments. Address translation involves page tables that map virtual to physical addresses, with demand paging loading pages from disk on-demand.

Uploaded by

Abram Jaz
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

MUZFFARPUR INSTITUTE OF TECHNOLOGY, MUZAFFAPUR

DEPARTMENT OF INFORMATION TECHNOLOGY

OPERATING SYSTEM

[106503P]

August – December, 2021

Assignment-2

Submitted To: Submitted By:

Mr. Ashish Kumar Md. Ibrahim


Hussain

Assistant Professor 18IT14/18106107901

Dept. of IT 5th Semester, IT


OS Assignment-2 18106107901

Index

S. No. Title Page No.

1. a) Define Deadlock and describe the necessary conditions for 2


deadlock

b) For the given situation (figure 1) where P, R and E denotes 3


processes, resource types and edges respectively. Consider
each resource has only one instance. Answer the following
questions.
i. Draw the Resource Allocation Graph
ii. Indicated Request and resource edges in the graph
iii. Draw the Wait-for graph iv. Is there a deadlock? Write the
answer with reason

c) What is the use of Banker’s Algorithm? Explain with very 3


clear details.

2. a) Differentiate between paging and segmentation. 4-5

b) Describe Page Table with specific details. 6

c) Write the steps of address translation by MMU and explain 7-8


demand loading of a page with clear diagram pointing out the
events and steps

3.a) What is critical section problem? Briefly write the 9


requirements of the solution of it.

b) Define Long-term, Medium-term and Short-term schedulers 10

4.a) Explain Inverted Page Table in detail. Clear diagram(s) must 10


be used to show the address translation.

b) Consider the following page reference string: 11


1, 2, 3, 4, 2, 1, 5, 6, 2, 1, 2, 3, 7, 6, 3, 2, 1, 2, 3, 6

Dept. of IT, MIT Muzaffarpur Page 1 of 11

OS Assignment-2 18106107901
Q.1. a) Define Deadlock and describe the necessary conditions for deadlock.

Answer: Deadlock is a situation where a set of processes are blocked because each process is
holding a resource and waiting for another resource acquired by some other process. 
Consider an example when two trains are coming toward each other on the same track and there
is only one track, none of the trains can move once they are in front of each other. A similar
situation occurs in operating systems when there are two or more processes that hold some
resources and wait for resources held by other(s).

Deadlock can arise if - following four conditions hold simultaneously (Necessary Conditions) 
Mutual Exclusion: Two or more resources are non-shareable (Only one process can use at a
time) 
Hold and Wait: A process is holding at least one resource and waiting for resources. 
No Preemption: A resource cannot be taken from a process unless the process releases the
resource. 
Circular Wait: A set of processes are waiting for each other in circular form. 
Methods for handling deadlock 
There are three ways to handle deadlock 
1) Deadlock prevention or avoidance: The idea is to not let the system into a deadlock state. 
One can zoom into each category individually, Prevention is done by negating one of above
mentioned necessary conditions for deadlock. 
Avoidance is kind of futuristic in nature. By using strategy of “Avoidance”, we have to make an
assumption. We need to ensure that all information about resources which process will need are
known to us prior to execution of the process. We use Banker’s algorithm (Which is in-turn a gift
from Dijkstra) in order to avoid deadlock. 
2) Deadlock detection and recovery: Let deadlock occur, then do preemption to handle it once
occurred. 
3) Ignore the problem altogether: If deadlock is very rare, then let it happen and reboot the
system. This is the approach that both Windows and UNIX take. 

Dept. of IT, MIT Muzaffarpur Page 2 of 11


OS Assignment-2 18106107901

Q. 1. b) For the given situation (figure 1) where P, R and E denotes processes, resource
types and edges respectively. Consider each resource has only one instance. Answer the
following questions.
i. Draw the Resource Allocation Graph
ii. Indicated Request and resource edges in the graph
iii. Draw the Wait-for graph iv. Is there a deadlock? Write the answer with reason.

Answer: Each process is waiting for a request resource.

Yes, it has deadlock as each process is dependent on other resources while other resource is
acquired by other processes. Hence, the process is waiting for infinitely times. Also circular wait
arises as it is single instance resource. So, deadlock arises.

Q. 1. c) What is the use of Banker’s Algorithm? Explain with very clear details.

Answer: The banker’s algorithm is a resource allocation and deadlock avoidance algorithm that
tests for safety by simulating the allocation for predetermined maximum possible amounts of all
resources, then makes an “s-state” check to test for possible activities, before deciding whether
allocation should be allowed to continue. Banker’s algorithm is named so because it is used in
banking system to check whether loan can be sanctioned to a person or not. Suppose there are n
number of account holders in a bank and the total sum of their money is S. If a person applies for
a loan then the bank first subtracts the loan amount from the total money that bank has and if the
remaining amount is greater than S then only the loan is sanctioned. It is done because if all the
account holders comes to withdraw their money then the bank can easily do it.
In other words, the bank would never allocate its money in such a way that it can no longer
satisfy the needs of all its customers. The bank would try to be in safe state always.

Dept. of IT, MIT Muzaffarpur Page 3 of 11


OS Assignment-2 18106107901

Q. 2. a) Differentiate between paging and segmentation.

Answer:

Paging

Paging is a memory management technique in which process address space is broken into blocks
of the same size called pages (size is power of 2, between 512 bytes and 8192 bytes). The size of
the process is measured in the number of pages. Similarly, main memory is divided into small
fixed-sized blocks of (physical) memory called frames and the size of a frame is kept the same as
that of a page to have optimum utilization of the main memory and to avoid external
fragmentation.
Similarly, main memory is divided into small fixed-sized blocks of (physical) memory called
frames and the size of a frame is kept the same as that of a page to have optimum utilization of
the main memory and to avoid external fragmentation.
Segmentation
Segmentation is a memory management technique in which each job is divided into several
segments of different sizes, one for each module that contains pieces that perform related
functions. Each segment is actually a different logical address space of the program. When a
process is to be executed, its corresponding segmentation are loaded into non-contiguous
memory though every segment is loaded into a contiguous block of available memory.
Segmentation memory management works very similar to paging but here segments are of
variable-length where as in paging pages are of fixed size.
A program segment contains the program's main function, utility functions, data structures, and
so on. The operating system maintains a segment map table for every process and a list of free
memory blocks along with segment numbers, their size and corresponding memory locations in
main memory. For each segment, the table stores the starting address of the segment and the
length of the segment. A reference to a memory location includes a value that identifies a
segment and an offset.

Dept. of IT, MIT Muzaffarpur Page 4 of 11


OS Assignment-2 18106107901

S.No. Paging Segmentation

1. In Paging, a process address space is In Segmentation, a process address space


broken into fixed sized blocks called is broken in varying sized blocks called
pages. sections.

2. Operating System divides the memory Compiler is responsible to calculate the


into pages. segment size, the virtual address and
actual address.

3. Page size is determined by available Section size is determined by the user.


memory.

4. Paging technique is faster in terms of Segmentation is slower than paging.


memory access.

5. Paging can cause internal fragmentation Segmentation can cause external


as some pages may go underutilized. fragmentation as some memory block
may not be used at all.

6. During paging, a logical address is During segmentation, a logical address is


divided into page number and page divided into section number and section
offset. offset.

7. During paging, a logical address is During segmentation, a logical address is


divided into page number and page divided into section number and section
offset. offset.

8. Page table stores the page data. Segmentation table stores the
segmentation data.

Dept. of IT, MIT Muzaffarpur Page 5 of 11


OS Assignment-2 18106107901

Q. 2. b) Describe Page Table with specific details.

Answer: Page Table is a data structure used by the virtual memory system to store the mapping
between logical addresses and physical addresses. Logical addresses are generated by the CPU
for the pages of the processes therefore they are generally used by the processes. Physical
addresses are the actual frame address of the memory. They are generally used by the hardware
or more specifically by RAM subsystems.
The image given below considers,
Physical Address Space = M words
Logical Address Space = L words
Page Size = P words

Physical Address = log 2 M = m bits


Logical Address = log 2 L = l bits
page offset = log 2 P = p bits

Dept. of IT, MIT Muzaffarpur Page 6 of 11


OS Assignment-2 18106107901

Q. 2. c) Write the steps of address translation by MMU and explain demand loading of a
page with clear diagram pointing out the events and steps.

Answer: The Memory Management Unit (MMU) is responsible for the translation of virtual
addresses used by software to physical addresses used in the memory system.

The MMU contains the following:

● The table walk unit, which contains logic that reads the translation tables from memory.
● Translation Look aside Buffers (TLBs), which cache recently used translations.

All memory addresses that are issued by software are virtual. These memory addresses are
passed to the MMU, which checks the TLBs for a recently used cached translation. If the MMU
does not find a recently cached translation, the table walk unit reads the appropriate table entry,
or entries, from memory, as shown here:

A virtual address must be translated to a physical address before a memory access can take place
(because we must know which physical memory location we are accessing). This need for
translation also applies to cached data, because on Armv6 and later processors, the data caches
store data using the physical address (addresses that are physically tagged). Therefore, the
address must be translated before a cache lookup can complete.

The translation tables work by dividing the virtual address space into equal-sized blocks and by
providing one entry in the table per block.
Entry 0 in the table provides the mapping for block 0, entry 1 provides the mapping for block 1,
and so on. Each entry contains the address of a corresponding block of physical memory and the
attributes to use when accessing the physical address.

Dept. of IT, MIT Muzaffarpur Page 7 of 11


OS Assignment-2 18106107901

A table lookup occurs when a translation takes place. When a translation happens, the virtual
address that is issued by the software is split in two as shown in table below:

This diagram shows a single-level lookup. The upper-order bits, which are labelled 'Which entry'
in the diagram, tell you which block entry to look in and they are used as an index into the table.
This entry block contains the physical address for the virtual address.
The lower-order bits, which are labelled 'Offset in block' in the diagram, are an offset within that
block and are not changed by the translation.

Dept. of IT, MIT Muzaffarpur Page 8 of 11


OS Assignment-2 18106107901

Q. 3. a) What is critical section problem? Briefly write the requirements of the solution of
it.

Answer: Critical Section is the part of a program which tries to access shared resources. That
resource may be any resource in a computer like a memory location, Data structure, CPU or any
IO device.
The critical section cannot be executed by more than one process at the same time; operating
system faces the difficulties in allowing and disallowing the processes from entering the critical
section.
The critical section problem is used to design a set of protocols which can ensure that the Race
condition among the processes will never arise.
In order to synchronize the cooperative processes, our main task is to solve the critical section
problem. We need to provide a solution in such a way that the following conditions can be
satisfied.

Requirements of Synchronization mechanisms

Primary

I. Mutual Exclusion : Our solution must provide mutual exclusion. By Mutual Exclusion,
we mean that if one process is executing inside critical section then the other process
must not enter in the critical section.
II. Progress : Progress means that if one process doesn't need to execute into critical section
then it should not stop other processes to get into the critical section.

Secondary
I. Bounded Waiting : We should be able to predict the waiting time for every process to get
into the critical section. The process must not be endlessly waiting for getting into the
critical section.
II. Architectural Neutrality : Our mechanism must be architectural natural. It means that if
our solution is working fine on one architecture then it should also run on the other ones
as well.

Dept. of IT, MIT Muzaffarpur Page 9 of 11


OS Assignment-2 18106107901

Q. 3. b) Define Long-term, Medium-term and Short-term schedulers.

Answer: Long Term Scheduler : Long term scheduler is also known as a job scheduler. This
schedule regulates the program and select process from the queue and loads them into memory
for execution. It also regulates the degree of multi-programming. However, the main goal of this
type of scheduler is to offer a balanced mix of jobs, like Processor, I/O jobs, that allows
managing multiprogramming.
Medium Term Scheduler: Medium-term scheduling is an important part of swapping. It enables
you to handle the swapped out-processes. In this scheduler, a running process can become
suspended, which makes an I/O request. A running process can become suspended if it makes an
I/O request. A suspended processes can’t make any progress towards completion. In order to
remove the process from memory and make space for other processes, the suspended process
should be moved to secondary storage.
Short Term Scheduler: Short term scheduling is also known as CPU scheduler. The main goal of
this scheduler is to boost the system performance according to set criteria. This helps you to
select from a group of processes that are ready to execute and allocates CPU to one of them. The
dispatcher gives control of the CPU to the process selected by the short term scheduler.
Q. 4. a) Explain Inverted Page Table in detail. Clear diagram(s) must be used to show the
address translation.
Answer: Inverted Page Table is the global page table which is maintained by the Operating
System for all the processes. In inverted page table, the number of entries is equal to the number
of frames in the main memory. It can be used to overcome the drawbacks of page table.

Q. 4. b) Consider the following page reference string:


1, 2, 3, 4, 2, 1, 5, 6, 2, 1, 2, 3, 7, 6, 3, 2, 1, 2, 3, 6
Showing the page table content, Find out how many page faults would occur for the
following
replacement algorithms in demand paging environment, assuming 4 frames are allocated ?
i. LRU replacement

Dept. of IT, MIT Muzaffarpur Page 10 of 11


OS Assignment-2 18106107901

ii. FIFO replacement


iii. Optimal replacement

Answer:

i. LRU Replacement: 4 frames are allocated.


44 4 466 6 66777 711 1 1
333 3 555 5 5333 3 33 3 33
222 2 2222 2 2222 2 22 2 22
1111 1 1111 1 1116 6 66 6 66
****HH**HHH***HH*HHH
10 page fault.

ii. FIFO Replacement:


44 4 444111111 222 22
333 3 33222226 666 666
2222 2 26666677 777 733
11111 1 55555333 331 111
****HH****H***H**H*H
14 page fault.
iii. Optimal Replacement:
44 4 566 6 6 666 6 6 66 6 6
333 3 333 3 3 333 3 3 33 3 3
2222 2 222 2 2 222 2 2 22 2 2
11111 1 111 1 1 177 7 7 11 1 1
****HH**HHHH*HHH*HHH
8 page fault.

Dept. of IT, MIT Muzaffarpur Page 11of 11

You might also like