os
-
Upload
suraj-singh -
Category
Documents
-
view
178 -
download
2
Transcript of os
Operating System
Homework-3
Submitted By:
Name: Suraj Kumar Singh
Section: E - 3004
Roll_No: RE3004B77
Group: 2
Course_code: 1604
Subject_code: CAP316
Submitted To:
Miss. jasleen
PART A
1 Consider the techniques of Swapping and overlays. Do they
have anything in common? Where do they differ in
implementation? Justify your answer.
Ans- Overlays:- Overlays is a memory management scheme. We can use
overlays to enable a process to be larger than the amount of memory
allocated to it. The idea of overlays is to keep in memory only those
instructions and data that are needed at any given time. When other
instructions are needed, they are loaded into space occupied previously by
instructions that are no longer needed, or In operating systems, an overlay is
when a process replaces itself with the code of another program
As in dynamic loading, overlays do not require any special
support from the operating system. They can be implemented completely by
user with simple file structures. The use of overlays is currently limited to
microcomputer and other systems that have limited amounts of physical
memory and that lack hardware support for more advanced techniques.
Swapping:- Swapping is a simple memory/process management
technique used by the operating system(os) to increase the utilization of the
processor by moving some blocked process from the main memory to the
secondary memory(hard disk). When you load a file or program, the file is
stored in the random access memory (RAM). Since RAM is finite, some files
cannot fit on it. These files are stored in a special section of the hard drive
called the "swap file". "Swapping" is the act of using this swap file.
A swapping is a mechanism in which a process can be swapped temporarily
out of memory to a backing store and then brought back into memory for
continued execution.
A variant of this swapping policy is used for priority-based scheduling
algorithms. If a higher-priority process arrives and wants service, the
memory manager can swap out the lower-priority process and then load and
execute the higher-priority process. When the higher-priority process
finishes, the lower-priority process can be swapped back in and continued.
This variant of swapping is sometimes called roll out, roll in.
Normally, a process that is swapped out will be swapped back into the same
memory space that it occupied previously. This restriction is dictated by the
method of address binding. If binding is done at assembly or load time, then
the process cannot be easily moved to a different location.
Implementation of overlay:-
Implementation of swapping:-
Read () 20KB
Function1()
50KB
Function2() 70
KB
Display () 40KB
Read()
(20kb)
Display ()
(40kb)
Function1()
(50kb)Function1()
(70kb)
Operating system
User
process/application
Process1
If we assume a data transfer rate of 1 megabyte/sec and access time of 10
milliseconds, then to actually transfer a 100Kbyte process we require:
Transfer Time = 100K / 1,000 = 1/10 seconds
= 100 milliseconds
Access time = 10 milliseconds
Total time = 110 milliseconds
As both the swap out and swap in should take place, the total swap time is
then about 220 milliseconds (above time is doubled). A round robin CPU
scheduling should have a time slot size much larger relative to swap time of
220 milliseconds. Also if process is not utilising memory space and just
waiting for I/O operation or blocked, it should be swapped.
2. A system uses multi-programming with variable no. of
tasks, with a memory of 110K for user processes. Draw the
memory map corresponding to the current memory
allocation table:
Proces2
A new job D arrives needing 15K of memory. Show the
memory allocation table entry for job D
using each the allocation strategy of first fit, best fit and worst
Ans-First fit:-
Job Base address Length
D 0 15
A 20 10
B 46 18
C 90 20
Best fit:-
Job Base address Length
A 20 10
D 31 15
B 46 18
C 90 20
Worst fit:-
Job Base address Length
A 20 10
B 46 18
D 65 15
C 90 20
3. Suppose a fixed partitioning memory system with partitions
of 100K, 500K, 200K, 300K and 600K (in memory order)
exists with all 5 partitions currently unused (or free).
a) Using the best fit algorithm, show the state of
memory after processes of 212K, 417K,
112K and 350K (in request order) arrive.
b) Using the best available algorithm, show the state of
memory after processes of 212K,
417K, 112K and 350K (in request order) arrive.
c) Compute the total internal
fragmentation for part (a), if any. d)
Compute the total external
fragmentation for part (b), if any.
Ans:- (a) Best fit:-
In the above figure, at memory space 500k, 83k memory space is left, at
200k, 88k memory space is left, at 300k, 82k memory space is left, at 600k,
250k memory space is left.
(b) from FIFO:-
Process 350 must be wait until release the memory space from other
process.
From best fit:-
From worst fit:-
Process 350 must be wait until release the memory space from other
process.
In the above figure “Best fit” is the best algorithm for memory allocation.
After allocated memory to the arrival processes the memory state is, at
memory space 500k, 83k memory space is left, at 200k, 88k memory space
is left, at 300k, 82k memory space is left, at 600k, 250k memory space is
left.
(c) Total internal fragmentation in part (a):-
(500K – 417K) + (200K – 112K) + (300K – 212K) +(600-350)
=83k+88k+88k+250k=509k.
(d) There is no any external fragmentation because there is no request in
pending.
P A R T B
4 Consider a logical address space of 8 pages of 1024 bytes
each, mapped onto a physical memory of 32 frames.
Determine the no. of bits in the logical address and that in
physical address.
Ans-
As was given for a 8 Page, 1024 words & 32 frames (shown below)
8 pages -> 2^3 bits
1024 bytes -> 2^10 bits
32 frames -> 2^5 bits
Therefore:
Logical memory = 3+10=13 bits (Page + Word)
Physical memory = 10 + 5 =15 bits (Word + Frame)
5. Consider the page reference string: 0, 1, 7, 0, 1, 2, 0, 1, 2, 3,
2, 7, 1, 0, 3, 1, 0, 3. Calculate the total no. of page faults
(with no pre-paging at all) using OPT, FIFO, LRU and Clock
algorithms such that 3 frames are allocated to the process
Ans-FIFO:-
0 1 7 0 1 2 0 1 2 3 2 7 1 0 3 1 0 3
0 0 0 2 2 2 3 3 3 1 1 1
1 1 1 0 0 0 2 2 2 0 0
7 7 7 1 1 1 7 7 7 3
total page faults=12.
OPT:-
0 1 7 0 1 2 0 1 2 3 2 7 1 0 3 1 0 3
0 0 0 0 3 3 3
1 1 1 1 1 1
7 2 2 7 0
Total page fault=7
LRU:-
0 1 7 0 1 2 0 1 2 3 2 7 1 0 3 1 0 3
0 0 0 0 3 3 1 1 3 3
1 1 1 1 7 7 7 7 1
7 2 2 2 2 0 0 0
Total page faults=10
6. A virtual memory system exhibits the follow trace of page nos.
as: 1,2,3,2,6,3,4,1,5,6,1,6,4,2.
Simulate the page replacements for the following scenarios:
a) FIFO
with 3
page
frames b)
FIFO with
4 page
frames
Determine the total no. of page faults for each. State whether
Belady’s anomaly occur?
Ans-
a) FIFO with 3 page frames:
1 2 3 2 6 3 4 1 5 6 1 6 4 2
1 1 1 6 6 6 5 5 5 2
2 2 2 4 4 4 6 6 6
3 3 3 1 1 1 4 4
Here Total Number of page faults = 10
a)FIFO With 4 page Frames :
1 2 3 2 6 3 4 1 5 6 1 6 4 2
1 1 1 1 4 4 4 4
2 2 2 2 1 1 1
3 3 3 3 5 5
6 6 6 6 2
Here Total Number of page Faults = 8
According to Belady’s Anomaly, When more frames are allotted to a
process(to accommodate more pages of the process), it generates more
page faults whereas it should be the other way round. As it should be the
other way round. But in the above case there is no Belady’s anomaly occure.