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

OS Mid Answers

The document discusses different memory management techniques like multiprogramming with fixed partitions, paging, and swapping. Multiprogramming with fixed partitions divides memory into fixed sized partitions. Paging maps logical addresses to physical addresses using a page table. Swapping temporarily moves processes between main memory and disk.

Uploaded by

Pranav Reddy
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

OS Mid Answers

The document discusses different memory management techniques like multiprogramming with fixed partitions, paging, and swapping. Multiprogramming with fixed partitions divides memory into fixed sized partitions. Paging maps logical addresses to physical addresses using a page table. Swapping temporarily moves processes between main memory and disk.

Uploaded by

Pranav Reddy
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

Q1.

Briefly describe multiprogramming with fixed partitions


A.
If we accept that multiprogramming is a good idea, we next need to
decide how to organize the available memory in order to make effective
use of the resource.

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.

There are a few drawbacks to this scheme.

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.

Using fixed partitions is easy to understand and implement, although


there are a number of drawbacks which we have outlined above.

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)

Q2(b). Explain the concept of swapping in memory management.


A.

Swapping is a memory management scheme in which any process can be


temporarily swapped from main memory to secondary memory so that the
main memory can be made available for other processes. It is used to
improve main memory utilization. In secondary memory, the place where
the swapped-out process is stored is called swap space.

The purpose of the swapping in operating system is to access the data


present in the hard disk and bring it to RAM so that the application
programs can use it. The thing to remember is that swapping is used only
when data is not present in RAM.
Example: Suppose the user process's size is 2048KB and is a standard
hard disk where swapping has a data transfer rate of 1Mbps. Now we will
calculate how long it will take to transfer from main memory to secondary
memory.

• User process size is 2048Kb


• Data transfer rate is 1Mbps = 1024 kbps
• Time = process size / transfer rate
• = 2048 / 1024
• = 2 seconds
• = 2000 milliseconds
• Now taking swap-in and swap-
out time, the process will take 4000 milliseconds.

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

semaphore mutex, wrt; // semaphore mutex is used to ensure mutual


exclusion when readcnt is updated i.e. when any reader enters or exit
from the critical section and semaphore wrt is used by both readers and
writers
int readcnt; // readcnt tells the number of processes performing read in
the critical section, initially 0
Functions for semaphore :

– wait() : decrements the semaphore value.

– signal() : increments the semaphore value.

Q5. Describe the various ways of organizing directories.


A.
A directory is a container that is used to contain folders and files. It
organizes files and folders in a hierarchical manner.
There are several logical structures of a directory, these are given below.
Single-level directory –
The single-level directory is the simplest directory structure. In it, all
files are contained in the same directory which makes it easy to support
and understand.
A single level directory has a significant limitation, however, when the
number of files increases or when the system has more than one user.
Since all the files are in the same directory, they must have a unique
name. if two users call their dataset test, then the unique name rule
violated.
Two-level directory –
As we have seen, a single level directory often leads to confusion of files
names among different users. the solution to this problem is to create a
separate directory for each user.
In the two-level directory structure, each user has their own user files
directory (UFD). The UFDs have similar structures, but each lists only
the files of a single user. system’s master file directory (MFD) is
searches whenever a new user id=s logged in. The MFD is indexed by
username or account number, and each entry points to the UFD for that
user.

Q6(a). Write short notes on sequential file organization.


A.
Sequential Access –
It is the simplest access method. Information in the file is processed in
order, one record after the other. This mode of access is by far the most
common; for example, editor and compiler usually access the file in this
fashion.
Read and write make up the bulk of the operation on a file. A read
operation -read next- read the next position of the file and automatically
advance a file pointer, which keeps track I/O location. Similarly, for the
write- write next append to the end of the file and advance to the newly
written material.

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.

Q6(b). Briefly describe the file protection mechanisms.


A.
Access Control :
There are different methods used by different users to access any file.
The general way of protection is to associate identity-dependent access
with all the files and directories an list called access-control list (ACL)
which specify the names of the users and the types of access associate
with each of the user. The main problem with the access list is their
length. If we want to allow everyone to read a file, we must list all the
users with the read access. This technique has two undesirable
consequences:

Constructing such a list may be tedious and unrewarding task, especially


if we do not know in advance the list of the users in the system.
Previously, the entry of the any directory is of the fixed size but now it
changes to the variable size which results in the complicates space
management. These problems can be resolved by use of a condensed
version of the access list. To condense the length of the access-control
list, many systems recognize three classification of users in connection
with each file:
Owner –
Owner is the user who has created the file.
Group –
A group is a set of members who has similar needs and they are sharing
the same file.
Universe –
In the system, all other users are under the category called universe.
The most common recent approach is to combine access-control lists
with the normal general owner, group, and universe access control
scheme. For example: Solaris uses the three categories of access by
default but allows access-control lists to be added to specific files and
directories when more fine-grained access control is desired.

Other Protection Approaches:


The access to any system is also controlled by the password. If the use of
password are is random and it is changed often, this may be result in
limit the effective access to a file.
The use of passwords has a few disadvantages:

The number of passwords are very large so it is difficult to remember the


large passwords.
If one password is used for all the files, then once it is discovered, all
files are accessible; protection is on all-or-none basis.

Q7. What is virtual memory? Discuss the benefits of virtual memory


techniques.
A.
Virtual Memory is a storage allocation scheme in which secondary
memory can be addressed as though it were part of main memory. The
addresses a program may use to reference memory are distinguished
from the addresses the memory system uses to identify physical storage
sites, and program generated addresses are translated automatically to
the corresponding machine addresses.
The size of virtual storage is limited by the addressing scheme of the
computer system and amount of secondary memory is available not by
the actual number of the main storage locations.

It is a technique that is implemented using both hardware and software.


It maps memory addresses used by a program, called virtual addresses,
into physical addresses in computer memory.

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 :

More processes may be maintained in the main memory: Because we are


going to load only some of the pages of any particular process, there is
room for more processes. This leads to more efficient utilization of the
processor because it is more likely that at least one of the more
numerous processes will be in the ready state at any particular time.
A process may be larger than all of main memory: One of the most
fundamental restrictions in programming is lifted. A process larger than
the main memory can be executed because of demand paging. The OS
itself loads pages of a process in main memory as required.
It allows greater multiprogramming levels by using less of the available
(primary) memory for each process.

Q9. Compare and contrast free space management and swap face
management.
A.

https://www.youtube.com/watch?v=plQHbnSkzLc – Free Space


Management
https://youtu.be/GOI2KABh8LQ - Swap Face Management
Q10. Describe dining philosopher problem. Define an algorithm to
solve the problem using semaphores.
A.
The Dining Philosopher Problem – The Dining Philosopher Problem
states that K philosophers seated around a circular table with one
chopstick between each pair of philosophers. There is one chopstick
between each philosopher. A philosopher may eat if he can pick up the
two chopsticks adjacent to him. One chopstick may be picked up by any
one of its adjacent followers but not both.

Semaphore Solution to Dining Philosopher –


Each philosopher is represented by the following pseudocode:
process P[i]
while true do
{ THINK;
PICKUP(CHOPSTICK[i], CHOPSTICK[i+1 mod 5]);
EAT;
PUTDOWN(CHOPSTICK[i], CHOPSTICK[i+1 mod 5])
}
There are three states of the philosopher: THINKING, HUNGRY, and
EATING. Here there are two semaphores: Mutex and a semaphore array
for the philosophers. Mutex is used such that no two philosophers may
access the pickup or putdown at the same time. The array is used to
control the behavior of each philosopher. But, semaphores can result in
deadlock due to programming errors.
Q11.Distinguish between paging and segmentation.
A.
Difference between Paging and Segmentation:

S.NO Paging Segmentation

In paging, program is divided


into fixed or mounted size In segmentation, program is divided
1. pages. into variable size sections.

For paging operating system is For segmentation compiler is


2. accountable. accountable.

Page size is determined by Here, the section size is given by the


3. hardware. user.

It is faster in the comparison


4. of segmentation. Segmentation is slow.

Paging could result in internal Segmentation could result in external


5. fragmentation. fragmentation.

In paging, logical address is


split into page number and Here, logical address is split into
6. page offset. section number and section offset.
S.NO Paging Segmentation

Paging comprises a page table While segmentation also comprises


which encloses the base the segment table which encloses
7. address of every page. segment number and segment offset.

Page table is employed to keep Section Table maintains the section


8. up the page data. data.

In paging, operating system In segmentation, operating system


must maintain a free frame maintain a list of holes in main
9. list. memory.

10. Paging is invisible to the user. Segmentation is visible to the user.

In paging, processor needs In segmentation, processor uses


page number, offset to segment number, offset to calculate
11. calculate absolute address. full address.
Q12. Describe
a. Linked Allocation Method
b. Indexed Allocation Method
A.
Linked List Allocation

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:

The pointer overhead for indexed allocation is greater than linked


allocation.
For very small files, say files that expand only 2-3 blocks, the indexed
allocation would keep one entire block (index block) for the pointers
which is inefficient in terms of memory utilization. However, in linked
allocation we lose the space of only 1 pointer per block.

You might also like