0% found this document useful (0 votes)
10 views7 pages

PQnA 15_16

The document discusses various scheduling algorithms, including FCFS and round-robin, providing calculations for average waiting and turnaround times for given processes. It also covers page replacement algorithms, virtual memory concepts, demand paging, and the differences between various memory management techniques. Additionally, it outlines procedures for handling page faults and compares logical vs physical addresses, page tables vs segment tables, and other memory allocation strategies.

Uploaded by

Abdullah Opadeji
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)
10 views7 pages

PQnA 15_16

The document discusses various scheduling algorithms, including FCFS and round-robin, providing calculations for average waiting and turnaround times for given processes. It also covers page replacement algorithms, virtual memory concepts, demand paging, and the differences between various memory management techniques. Additionally, it outlines procedures for handling page faults and compares logical vs physical addresses, page tables vs segment tables, and other memory allocation strategies.

Uploaded by

Abdullah Opadeji
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/ 7

CSC 314 2015/2016 PQ

Some questions may contain more than 1 answer so pick the one you find
short and easy to memorize.

SECTION II

1a. Find the average waiting time and average turnaround time for executing the following
processes using FCFS (first-come first-service) scheduling?

Process Burst time

P0 7

P1 5

P2 2

P3 9

The average waiting time and average turnaround time for a set of processes can be calculated
using the following formulas:

Average waiting time = (waiting time for P0 + waiting time for P1 + waiting time for P2 +
waiting time for P3) / number of processes
Average turnaround time = (turnaround time for P0 + turnaround time for P1 + turnaround time
for P2 + turnaround time for P3) / number of processes

In the case of FCFS scheduling, the waiting time for a process is equal to the sum of the burst
times of all the processes that have arrived before it, and the turnaround time is equal to the
waiting time plus the burst time of the process itself.

Using this information, we can calculate the average waiting time and average turnaround time
for the processes above as follows:
● P0: waiting time = 0, turnaround time = 0 + 7 = 7
● P1: waiting time = 7, turnaround time = 7 + 5 = 12
● P2: waiting time = 12, turnaround time = 12 + 2 = 14
● P3: waiting time = 14, turnaround time = 14 + 9 = 23
Therefore, the average waiting time is (0 + 7 + 12 + 14) / 4 = 33 / 4 = 8.25 and the average
turnaround time is (7 + 12 + 14 + 23) / 4 = 56 / 4 = 14.
1b. Find the average waiting time (A.W.T.) and the average turnaround time (A.T.A.T.) for
executing the following processes using round-robin algorithm, where time quantum is 5?

Process P1 P2 P3 P4 P5

Burst time 11 4 14 9 21

Arrival time 5 0 0 1 2

To calculate the average waiting time (A.W.T.) and average turnaround time (A.T.A.T.) for a set
of processes using the round-robin algorithm, we can use the following steps:
1. Assign a time quantum (TQ) to each process. In this case, the time quantum is 5.
2. Calculate the turnaround time for each process by subtracting its arrival time from its
completion time. The completion time for a process is the time at which it finishes
executing, which can be calculated by adding the time quantum to the time at which it
starts executing. If the burst time of a process is less than the time quantum, then the
completion time is equal to the burst time.
3. Calculate the waiting time for each process by subtracting its turnaround time from its
burst time.
4. Calculate the average waiting time (A.W.T.) by summing the waiting times for all
processes and dividing by the total number of processes.
5. Calculate the average turnaround time (A.T.A.T.) by summing the turnaround times for
all processes and dividing by the total number of processes.

Using these steps, we can calculate the A.W.T. and A.T.A.T. for the processes given in the
question as follows:
Process Arrival time Burst time Completion time Turnaround time Waiting time

P1 5 11 16 11 0

P2 0 4 5 5 1

P3 0 14 19 19 5

P4 1 9 10 9 0

P5 2 21 27 25 4
A.W.T. = (0 + 1 + 5 + 0 + 4)/5 = 2.2
A.T.A.T. = (11 + 5 + 19 + 9 + 25)/5 = 14.4
Therefore, the average waiting time (A.W.T.) and average turnaround time (A.T.A.T.) for the
processes using the round-robin algorithm with a time quantum of 5 are 2.2 and 14.4,
respectively.

2a. What are the operations of page replacement algorithm?


● FIFO (First In, First Out): In this algorithm, the operating system maintains a queue of
pages in memory. When a new page needs to be loaded, the operating system evicts the
page that has been in memory the longest.
● LRU (Least Recently Used): In this algorithm, the operating system maintains a record of
which pages have been used recently. When a new page needs to be loaded, the operating
system evicts the page that has not been used for the longest period of time.
● LFU (Least Frequently Used): In this algorithm, the operating system maintains a record
of how often each page in memory has been used. When a new page needs to be loaded,
the operating system evicts the page that has been used the fewest number of times.

2b. What are the principles of the following replacement algorithms? a) FIFO. b) LRU.
The principle of the FIFO algorithm is that the first page that is loaded into memory will be the
first one to be replaced when a new page needs to be loaded. This means that the page that has
been in memory the longest will be replaced.

The principle of the LRU algorithm is that the page that has not been used for the longest time
will be replaced. This means that the page that was least recently used will be replaced. This
algorithm is based on the assumption that pages that have not been used recently are less likely
to be used in the near future.

2c. Define the virtual memory? Outline 4 of its advantages?


Virtual memory is a feature of an operating system (OS) that enables a computer to be able to
compensate for shortages of physical memory by temporarily transferring pages of data from
random access memory (RAM) to disk storage. This allows a computer to be able to run larger
programs or multiple programs at the same time.
Advantages:
1. Virtual memory enables a computer to run larger programs or multiple programs at the
same time, even if it does not have enough physical memory to do so.
2. It allows programs to be executed more efficiently, because the OS can manage the
allocation of memory more effectively.
3. Virtual memory provides a degree of protection for the system and its programs, because
it can prevent programs from interfering with each other or with the OS.
4. It can help to increase the security of a system, because it can prevent programs from
being able to access sensitive data that is stored in memory.

More advantages:

● Virtual memory helps to gain speed when only a particular segment of the program is
required for the execution of the program.
● It is very helpful in implementing a multiprogramming environment.
● It allows you to run more applications at once.
● It helps you to fit many large programs into smaller programs.
● Common data or code may be shared between memory.
● Process may become even larger than all of the physical memory.
● Data / code should be read from disk whenever required.
● The code can be placed anywhere in physical memory without requiring relocation.
● More processes should be maintained in the main memory, which increases the effective
use of CPU.
● Each page is stored on a disk until it is required after that, it will be removed.
● It allows more applications to be run at the same time.
● There is no specific limit on the degree of multiprogramming.
● Large programs should be written, as virtual address space available is more compared to
physical memory.

2d. Define demand paging? Give 5 advantages of using pager (i.e. demand paging)?

Demand paging is a technique used by an operating system (OS) to manage virtual memory. It
allows a computer to load pages of data from disk storage into RAM only when they are needed,
rather than pre-loading all data into memory when a program is launched.
Advantages
1. It allows a computer to run larger programs or multiple programs at the same time, even
if it does not have enough physical memory to do so.
2. It can help to increase the efficiency of the system, because it reduces the amount of
memory that is wasted on unused data.
3. Demand paging can improve the performance of a system, because it allows the OS to
load data from disk into memory more quickly and efficiently.
4. It provides a degree of protection for the system and its programs, because it can prevent
programs from interfering with each other or with the OS.
5. It can help to increase the security of a system, because it can prevent programs from
being able to access sensitive data that is stored in memory.

2e. Outline 2 differences between pager and swapper?


1. A pager is a component of an operating system (OS) that manages virtual memory, while
a swapper is a different component of the OS that is responsible for swapping processes
in and out of memory.
2. A pager is responsible for loading pages of data from disk storage into RAM on demand,
while a swapper is responsible for moving processes from RAM to disk storage and vice
versa, in order to free up space in memory for other processes.

2f. How does page faults occur? Briefly explain 6 procedures for handling page fault?
A page fault occurs when a program tries to access a memory page that is currently not stored in
main memory. This can happen because the page has been swapped out to secondary storage, or
because it has never been accessed before and is therefore not loaded in memory.
OR
A page fault occurs when a program attempts to access a page of data that is not currently
resident in physical memory
OR
A page fault occurs when a program tries to access a page in memory that is not currently
mapped to that program's address space. This can happen for a variety of reasons, such as when a
program tries to access data that it hasn't used in a while and the operating system has
temporarily moved that data to disk to free up space in memory for other programs.
Procedures
1. The OS can simply terminate the program that caused the page fault, if it is unable to
recover from the fault.
2. The OS can attempt to load the required page of data from disk storage into memory, and
then allow the program to access the data.
3. The OS can attempt to swap out a different page of data from memory in order to make
room for the required page, and then load the required page from disk.
4. The OS can attempt to repair any corruption in the required page of data, and then allow
the program to access the data.
5. The OS can temporarily suspend the execution of the program that caused the page fault,
and allow other programs to continue running.
6. The OS can generate an error message or other notification to alert the user that a page
fault has occurred, and provide instructions for how to resolve the issue.
OR
1. Demand paging: The operating system can allocate a new page in memory for the
program to use and copy the data from the disk into the new page.
2. Page replacement: The operating system can choose a page that is currently being used
by another program and swap it out with the page that the faulting program needs.
3. Prefetching: The operating system can anticipate future page faults and load the
necessary pages into memory before they are actually needed.
4. Lazy loading: The operating system can delay loading a page until it is actually needed.
5. Segmentation: The operating system can divide a program's address space into smaller
units called segments, and only load the segments that are actually needed.
6. Paging: The operating system can divide a program's address space into smaller units
called pages, and only load the pages that are actually needed.
OR
1. Check if the page that caused the fault is present in the backing store. If it is, copy it into
memory and update the page table to reflect the change.
2. If the page is not present in the backing store, allocate a new page in memory and update
the page table to reflect the change.
3. If there is not enough free memory to allocate a new page, select a page that is currently
mapped to the address space but not being used, and write it to the backing store. This is
known as "page swapping" or "page replacement".
4. Once a page has been swapped out or a new page has been allocated, the program can
continue execution as if the page fault never occurred.
5. If the page fault was caused by a program attempting to write to a read-only page,
terminate the program with an error message.
6. If the page fault was caused by a program attempting to access an invalid memory
address, terminate the program with an error message.

3a. To measure the demand paging, the effective access time for a demand -paged memory
is calculated by: Effective access time = (1 - p) x ma + p x page fault time Where p: The
probability of page fault, O < p < 1; ma: Memory access time, ranges from 10 to 200
nanosecond. Assume an average page-fault service time is 25 milliseconds and a memory
access time is 100 nanoseconds. Find the Effective Access Time?

3b. What are the differences between;


i) Logical and physical address?
ii) Page table and segment table?
iii) First-fit placement and best-fit placement?
iv) Contiguous and non contiguous storage allocation
v) Multiple contiguous fixed partitions (MFT) and multiple contiguous variable partitions
(MVT).
vi) Segmentation and paging storage?

i) A logical address is an address that is generated by the CPU and is used by the program being
executed. A physical address is the actual address of a memory location on the physical memory
device.

ii) A page table is a data structure that is used to store the mapping between logical addresses and
physical addresses in a paging system. A segment table is a data structure that is used to store the
mapping between logical addresses and physical addresses in a segmentation system.

iii) First-fit placement is a memory allocation algorithm in which the first free block of sufficient
size is chosen to allocate to a process. Best-fit placement is a memory allocation algorithm in
which the smallest free block of sufficient size is chosen to allocate to a process.

iv) Contiguous storage allocation is a method of allocating memory in which a contiguous block
of memory is assigned to a process. Non-contiguous storage allocation is a method of allocating
memory in which multiple blocks of memory are assigned to a process, but these blocks are not
necessarily contiguous.

v) Multiple contiguous fixed partitions (MFT) is a method of allocating memory in which the
memory is divided into a number of fixed-size partitions. Multiple contiguous variable partitions
(MVT) is a method of allocating memory in which the memory is divided into a number of
variable-size partitions.

vi) Segmentation is a memory management technique in which the memory is divided into a
number of fixed-size or variable-size segments. Paging is a memory management technique in
which the memory is divided into a number of fixed-size blocks called pages. In segmentation,
the mapping between logical addresses and physical addresses is done using a segment table,
while in paging, the mapping is done using a page table.

You might also like