OS Mid Answers
OS Mid Answers
One method is to divide the memory into fixed sized partitions. These
partitions can be of different sizes but once a partition has taken on a
certain size then it remains at that size. There is no provision for
changing its size.
The IBM OS/360 was set up in this way. The computer operator defined
the sizes of the partitions in the morning (or when the machine was
booted) and these partitions remained in effect until the computer was
reloaded. This was called MFT (Multiprogramming with Fixed number
of Tasks - or OS/MFT)
The diagram above shows how this scheme might work. The memory is
divided into four partitions (we'll ignore the operating system). When a
job arrives it is placed in the input queue for the smallest partition that
will accommodate it.
1. As the partition sizes are fixed, any space not used by a particular job
is lost.
2. It may not be easy to state how big a partition a particular job needs.
3. If a job is placed in (say) queue three it may be prevented from
running by other jobs waiting (and using) that partition.
To cater for the last problem we could have a single input queue where
all jobs are held. When a partition becomes free, we search the queue
looking for the first job that fits into the partition. An alternative search
strategy is to search the entire input queue looking for the largest job that
fits into the partition. This has the advantage that we do not waste a large
partition on a small job but has the disadvantage that smaller jobs are
discriminated against. Smaller jobs are typically interactive jobs which
we normally want to service first.
To ensure small jobs do get run we could have at least one small
partition or ensure that small jobs only get skipped a certain number of
times.
Last Page
Q2(a) . Write a short note on paging with an example.
A.
Paging in Operating System
• Difficulty Level : Medium
• Last Updated : 28 Jun 2021
Paging is a memory management scheme that eliminates the need for
contiguous allocation of physical memory. This scheme permits the
physical address space of a process to be non – contiguous.
• Logical Address or Virtual Address (represented in bits): An address
generated by the CPU
• Logical Address Space or Virtual Address Space( represented in
words or bytes): The set of all logical addresses generated by a
program
• Physical Address (represented in bits): An address available on
memory unit
• Physical Address Space (represented in words or bytes): The set of all
physical addresses corresponding to the logical addresses
Example:
31
• If Logical Address = 31 bit, then Logical Address Space = 2 words
= 2 G words (1 G = 230)
7 20
• If Logical Address Space = 128 M words = 2 * 2 words, then
Logical Address = log2 227 = 27 bits
• If Physical Address = 22 bit, then Physical Address Space =
222 words = 4 M words (1 M = 220)
4 20
• If Physical Address Space = 16 M words = 2 * 2 words, then
Physical Address = log2 224 = 24 bits
The mapping from virtual to physical address is done by the memory
management unit (MMU) which is a hardware device and this mapping
is known as paging technique.
• The Physical Address Space is conceptually divided into several
fixed-size blocks, called frames.
• The Logical address Space is also split into fixed-size blocks,
called pages.
• Page Size = Frame Size
Let us consider an example:
• Physical Address = 12 bits, then Physical Address Space = 4 K words
• Logical Address = 13 bits, then Logical Address Space = 8 K words
• Page size = frame size = 1 K words (assumption)
Q4. Explain the reader’s writer’s problem and its solution using the
concept of semaphores.
A.
Consider a situation where we have a file shared between many people.
• If one of the people tries editing the file, no other person should be
reading or writing at the same time, otherwise changes will not be
visible to him/her.
However if some person is reading the file, then others may read it
at the same time.
Precisely in OS we call this situation as the readers-writers problem
Problem parameters:
• One set of data is shared among several processes
• Once a writer is ready, it performs its write. Only one writer may
write at a time
• If a process is writing, no other process can read it
• If at least one reader is reading, no other process can write
• Readers may not write and only read
Three variables are used: mutex, wrt, readcnt to implement solution
Key points:
• Data is accessed one record right after another record in an order.
• When we use read command, it move ahead pointer by one
• When we use write command, it will allocate memory and move
the pointer to the end of the file
• Such a method is reasonable for tape.
All memory references within a process are logical addresses that are
dynamically translated into physical addresses at run time. This means
that a process can be swapped in and out of main memory such that it
occupies different places in main memory at different times during the
course of execution.
A process may be broken into number of pieces and these pieces need
not be continuously located in the main memory during execution. The
combination of dynamic run-time address translation and use of page or
segment table permits this.
Advantages :
Q9. Compare and contrast free space management and swap face
management.
A.
In this scheme, each file is a linked list of disk blocks which need not be
contiguous. The disk blocks can be scattered anywhere on the disk.
The directory entry contains a pointer to the starting and the ending file
block. Each block contains a pointer to the next block occupied by the
file.
The file ‘jeep’ in following image shows how the blocks are randomly
distributed. The last block (25) contains -1 indicating a null pointer and
does not point to any other block.
Linked
Advantages:
This is very flexible in terms of file size. File size can be increased
easily since the system does not have to look for a contiguous chunk of
memory.
This method does not suffer from external fragmentation. This makes it
relatively better in terms of memory utilization.
Disadvantages:
Because the file blocks are distributed randomly on the disk, a large
number of seeks are needed to access every block individually. This
makes linked allocation slower.
It does not support random or direct access. We can not directly access
the blocks of a file. A block k of a file can be accessed by traversing k
blocks sequentially (sequential access ) from the starting block of the file
via block pointers.
Pointers required in the linked allocation incur some extra overhead.
Indexed Allocation
In this scheme, a special block known as the Index block contains the
pointers to all the blocks occupied by a file. Each file has its own index
block. The ith entry in the index block contains the disk address of the ith
file block. The directory entry contains the address of the index block as
shown in the image:
indexed
Advantages:
This supports direct access to the blocks occupied by the file and
therefore provides fast access to the file blocks.
It overcomes the problem of external fragmentation.
Disadvantages: