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

Principles of Operating System Questions and Answers

The document contains questions and answers related to operating system concepts. (1) It discusses the concepts of swapping, thrashing, demand paging, and virtual memory. Swapping involves temporarily removing a process from memory. Thrashing occurs when too much time is spent swapping pages in and out. Demand paging loads pages on demand when a page fault occurs. Virtual memory allows processes to access more memory than is physically available. (2) It provides details on paging and segmentation. Paging maps logical addresses to physical addresses using page tables. Segmentation divides a process into variable sized segments. (3) It differentiates between contiguous and non-contiguous memory allocation, with contiguous alloc

Uploaded by

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

Principles of Operating System Questions and Answers

The document contains questions and answers related to operating system concepts. (1) It discusses the concepts of swapping, thrashing, demand paging, and virtual memory. Swapping involves temporarily removing a process from memory. Thrashing occurs when too much time is spent swapping pages in and out. Demand paging loads pages on demand when a page fault occurs. Virtual memory allows processes to access more memory than is physically available. (2) It provides details on paging and segmentation. Paging maps logical addresses to physical addresses using page tables. Segmentation divides a process into variable sized segments. (3) It differentiates between contiguous and non-contiguous memory allocation, with contiguous alloc

Uploaded by

kumar nikhil
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

DRONACHARYA COLLEGE OF ENGINEERING, GURGAON

Second Sessional Examination October 2019


SESSIONAL QUESTION & ANSWER
Subject with Code: Principles of Operating System (CSE-301-F)
Semester: V Branch: CSE
Q. 1. Write short Note on: -
(a) Explain the concept of swapping?
 A process must be in memory to be executed.
 A process, however, can be swapped temporarily out of memory to a backing
store and then brought back into memory for continued execution.

Swapping a process out means removing all of its pages from memory, or marking them
so that they will be removed by the normal page replacement process. Suspending a
process ensures that it is not runnable while it is swapped out. At some later time, the
system swaps back the process from the secondary storage to main memory.

(b) What do you mean by thrashing?


When a process is busy swapping pages in and out then this situation is called thrashing.
At any given time, only few pages of any process are in main memory and therefore more
processes can be maintained in memory. Furthermore time is saved because unused pages
are not swapped in and out of memory. However, the OS must be clever about how it
manages this scheme. In the steady state practically, all of main memory will be occupied
with process’s pages, so that the processor and OS has direct access to as many processes
as possible. Thus when the OS brings one page in, it must throw another out. If it throws
out a page just before it is used, then it will just have to get that page again almost
immediately. Too much of this leads to a condition called Thrashing. The system spends
most of its time swapping pages rather than executing instructions.

(c) Explain meaning of demand paging?


The process of loading the page into memory on demand (whenever page fault occurs) is
known as demand paging.

The process includes the following steps:

1. If CPU try to refer a page that is currently not available in the main memory, it generates
an interrupt indicating memory access fault.
2. The OS puts the interrupted process in a blocking state. For the execution to proceed the
OS must bring the required page into the memory.
3. The OS will search for the required page in the logical address space.
4. The required page will be brought from logical address space to physical address space.
The page replacement algorithms are used for the decision making of replacing the page
in physical address space.
5. The page table will updated accordingly.
6. The signal will be sent to the CPU to continue the program execution and it will place the
process back into ready state

Hence whenever a page fault occurs these steps are followed by the operating system and
the required page is brought into memory.
(d) What do you mean by Virtual Memory?
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.
If these characteristics are present then, it is not necessary that all the pages or segments
are present in the main memory during execution. This means that the required pages
need to be loaded into memory whenever required. Virtual memory is implemented using
Demand Paging or Demand Segmentation.

(e) Differentiate between contiguous and non-contiguous memory allocations with


example.
Memory is a large array of bytes, where each byte has its own address. The memory
allocation can be classified into two methods contiguous memory allocation and non-
contiguous memory allocation. The major difference between Contiguous and
Noncontiguous memory allocation is that the contiguous memory allocation assigns the
consecutive blocks of memory to a process requesting for memory whereas, the
noncontiguous memory allocation assigns the separate memory blocks at the different
location in memory space in a nonconsecutive manner to a process requesting for
memory. We will discuss some more differences between contiguous and non-contiguous
memory allocation with the help of comparison chart shown below.

Basis the
Contiguous Memory Allocation Noncontiguous Memory Allocation
Comparison
Allocates consecutive blocks of Allocates separate blocks of memory
Basic
memory to a process. to a process.
Contiguous memory allocation does
Noncontiguous memory allocation has
not have the overhead of address
Overheads overhead of address translation while
translation while execution of a
execution of a process.
process.
A process executes quite slower
Execution A process executes fatser in
comparatively in noncontiguous
rate contiguous memory allocation
memory allocation.
The memory space must be divided Divide the process into several blocks
into the fixed-sized partition and each and place them in different parts of the
Solution
partition is allocated to a single memory according to the availability
process only. of memory space available.
A table is maintained by operating A table has to be maintained for each
system which maintains the list of process that carries the base addresses
Table
available and occupied partition in the of each block which has been acquired
memory space by a process in memory.

SECTION-A

Q2: Explain paging and Segmentation in detail with suitable diagram and example?

Answer: - Paging in Operating System: 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: 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 actually available on memory unit
 Physical Address Space (represented in words or bytes): The set of all physical addresses
corresponding to the logical addresses

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 a number of fixed-size blocks,
called frames.
 The Logical address Space is also splitted 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)

Address generated by CPU is divided into:

 Page number(p): Number of bits required to represent the pages in Logical Address
Space or Page number
 Page offset(d): Number of bits required to represent particular word in a page or page
size of Logical Address Space or word number of a page or page offset.

Physical Address is divided into:

 Frame number(f): Number of bits required to represent the frame of Physical Address
Space or Frame number.
 Frame offset(d): Number of bits required to represent particular word in a frame or
frame size of Physical Address Space or word number of a frame or frame offset.

Segmentation in Operating System: A process is divided into Segments. The chunks that a
program is divided into which are not necessarily all of the same sizes are called segments.
Segmentation gives user’s view of the process which paging does not give. Here the user’s view
is mapped to physical memory. There are types of segmentation:

1. Virtual memory segmentation –


Each process is divided into a number of segments, not all of which are resident at any
one point in time.
2. Simple segmentation –
Each process is divided into a number of segments, all of which are loaded into memory
at run time, though not necessarily contiguously.
There is no simple relationship between logical addresses and physical addresses in
segmentation. A table stores the information about all such segments and is called Segment
Table.

Segment Table – It maps two-dimensional Logical address into one-dimensional Physical


address. It’s each table entry has:

 Base Address: It contains the starting physical address where the segments reside in
memory.
 Limit: It specifies the length of the segment.

Translation of Two dimensional Logical Address to one dimensional Physical Address.

Address generated by the CPU is divided into:

 Segment number (s): Number of bits required to represent the segment.


 Segment offset (d): Number of bits required to represent the size of the segment.
Q3: Give the brief overview of various page replacement algorithms and consider the
following page reference string:- 7,0,1,2,0,3,0,4,2,3,0,3,2,1,2,0,1,7,0,1. How many page faults
would occur for the following page replacement algorithms assuming 3 frames:
i) FIFO ii) Optimal iii) LRU

Answer: - In an operating system that uses paging for memory management, a page replacement
algorithm is needed to decide which page needs to be replaced when new page comes in.

Page Fault: A page fault happens when a running program accesses a memory page that is
mapped into the virtual address space, but not loaded in physical memory.

Page Replacement Algorithms:-


(i) First In First Out (FIFO) :- In this algorithm, the operating system keeps track of all
pages in the memory in a queue, the oldest page is in the front of the queue. When a
page needs to be replaced page in the front of the queue is selected for removal.

In FIFO algorithm 15 page fault will occur.

(ii) Optimal Page replacement:- In this algorithm, pages are replaced which would not be
used for the longest duration of time in the future.

In optimal algorithm 9 page fault will occur.

(iii)Least Recently Used (LRU):- In this algorithm page will be replaced which is least
recently used.

In LRU algorithm 12 page fault will occur.


SECTION B

Q4: What do you mean by file? Discuss different types of file access and file allocation
methods with suitable examples?

Answer: - A file is a collection of related information that is recorded on secondary storage. Or


file is a collection of logically related entities. From user’s perspective a file is the smallest
allotment of logical secondary storage.

Attributes Types Operations


Name Doc Create
Type Exe Open
Size Jpg Read
Creation Data Xis Write
Author C Append
Last Modified Java Truncate
protection class Delete
Close
File Allocation Methods: The allocation methods define how the files are stored in the disk
blocks. There are three main disk space or file allocation methods:
 Contiguous Allocation
 Linked Allocation
 Indexed Allocation

(i). Continuous Allocation: A single continuous set of blocks is allocated to a file at the time of
file creation. Thus, this is a pre-allocation strategy, using variable size portions. The file
allocation table needs just a single entry for each file, showing the starting block and the length
of the file.
Disadvantage

 External fragmentation will occur, making it difficult to find contiguous blocks of space
of sufficient length. Compaction algorithm will be necessary to free up additional space
on disk.
 Also, with pre-allocation, it is necessary to declare the size of the file at the time of
creation.

(ii). Linked Allocation (Non-contiguous allocation): Allocation is on an individual block basis.


Each block contains a pointer to the next block in the chain. Again the file table needs just a
single entry for each file, showing the starting block and the length of the file. Although pre-
allocation is possible, it is more common simply to allocate blocks as needed. Any free block can
be added to the chain. The blocks need not be continuous. Increase in file size is always possible
if free disk block is available. There is no external fragmentation because only one block at a
time is needed but there can be internal fragmentation but it exists only in the last disk block of
file.

Disadvantage:

 Internal fragmentation exists in last disk block of file.


 There is an overhead of maintaining the pointer in every disk block.
 If the pointer of any disk block is lost, the file will be truncated.
 It supports only the sequencial access of files.

(iii). Indexed Allocation: It addresses many of the problems of contiguous and chained
allocation. In this case, the file allocation table contains a separate one-level index for each file:
The index has one entry for each block allocated to the file. Allocation may be on the basis of
fixed-size blocks or variable-sized blocks. Allocation by blocks eliminates external
fragmentation, whereas allocation by variable-size blocks improves locality. This allocation
technique supports both sequential and direct access to the file and thus is the most popular form
of file allocation.
File Access Methods in Operating System
When a file is used, information is read and accessed into computer memory and there are
several ways to access this information of the file. Some systems provide only one access
method for files. Other systems, such as those of IBM, support many access methods, and
choosing the right one for a particular application is a major design problem.
There are three ways to access a file into a computer system: Sequential-Access, Direct Access,
Index sequential Method.

(i). 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.

 Read operation: read next read the next position of the file and automatically advance a
file pointer, which keeps track I/O location.
 Write operation: write next append to the end of the file and advance to the newly
written material.

(ii). Direct Access: Another method is direct access method also known as relative access
method. A filed length logical record that allows the program to read and write record rapidly. in
no particular order. The direct access is based on the disk model of a file since disk allows
random access to any file block. For direct access, the file is viewed as a numbered sequence of
block or record.

(iii). Index sequential method: It is the other method of accessing a file which is built on the
top of the direct access method. These methods construct an index for the file. The index, like an
index in the back of a book, contains the pointer to the various blocks. To find a record in the
file, we first search the index and then by the help of pointer we access the file directly.
Q5: (a) Explain File System and Shell Interpreter in UNIX?

Answer: - Unix File System:- Unix file system is a logical method of organizing and storing
large amounts of information in a way that makes it easy to manage. A file is a smallest unit in
which the information is stored. Unix file system has several important features. All data in Unix
is organized into files. All files are organized into directories. These directories are organized
into a tree-like structure called the file system.

Files in Unix System are organized into multi-level hierarchy structure known as a directory tree.
At the very top of the file system is a directory called “root” which is represented by a “/”. All
other files are “descendants” of root.

Types of Unix files – The UNIX files system contains several different types of files :

(i). Ordinary files: An ordinary file is a file on the system that contains data, text, or program
instructions.

(ii). Directories: A directory file contains an entry for every file and subdirectory that it houses.
(iii). Special Files: Used to represent a real physical device such as a printer, tape drive or
terminal, used for Input/Ouput (I/O) operations.

(iv). Pipes: The pipe acts a temporary file which only exists to hold data from one command
until it is read by another.

(v). Sockets – A Unix socket is a special file which allows for advanced inter-process
communication.

(vi). Symbolic Link – Symbolic link is used for referencing some other file of the file system.

Shell Interpreter in UNIX: The shell is your interface with the Unix system, the middleman
between you and the kernel. The shell is a type of program called an interpreter. An interpreter
operates in a simple loop: It accepts a command, interprets the command, executes the
command, and then waits for another command.

A kernel is a program that:

 Controls all computer operations.


 Coordinates all executing utilities
 Ensures that executing utilities do not interfere with each other or consume all system
resources.
 Schedules and manages all system processes.

By interfacing with a kernel, a shell provides a way for a user to execute utilities and programs.

Types of Shells:

The following sections describe OS shells mostly available on UNIX/Linux Operating system.
Shell features and their default prompts are also described.

(i). The Bourne Shell: The Bourne shell (sh), written by Steve Bourne at AT&T Bell Labs, is
the original UNIX shell. It is the preferred shell for shell programming because of its
compactness and speed. A Bourne shell drawback is that it lacks features for interactive use,
such as the ability to recall previous commands (history). The Bourne shell also lacks built-in
arithmetic and logical expression handling.

The Bourne shell is the Solaris OS default shell. It is the standard shell for Solaris system
administration scripts. For the Bourne shell the:

 Command full-path name is /bin/sh and /sbin/sh.


 Non-root user default prompt is $.
 Root user default prompt is #.

(ii). The C Shell: The C shell (csh):

 Is a UNIX enhancement written by Bill Joy at the University of California at


Berkeley.
 Incorporated features for interactive use, such as aliases and command history.
 Includes convenient programming features, such as built-in arithmetic and a C-
like expression syntax.
For the C shell the:

 Command full-path name is /bin/csh.


 Non-root user default prompt is hostname %.
 Root user default prompt is hostname #.

(iii). The Korn Shell: The Korn shell (ksh):

 Was written by David Korn at AT&T Bell Labs


 Is a superset of the Bourne shell.
 Supports everything in the Bourne shell.
 Has interactive features comparable to those in the C shell.
 Includes convenient programming features like built-in arithmetic and C-like
arrays, functions, and string-manipulation facilities.
 Is faster than the C shell.
 Runs scripts written for the Bourne shell.

For the Korn shell the:

 Command full-path name is /bin/ksh.


 Non-root user default prompt is $.
 Root user default prompt is #.

(iv). The GNU Bourne-Again Shell: The GNU Bourne-Again shell (bash):

 Is compatible to the Bourne shell.


 Incorporates useful features from the Korn and C shells.
 Has arrow keys that are automatically mapped for command recall and editing.

For the GNU Bourne-Again shell the:


 Command full-path name is /bin/bash.
 Default prompt for a non-root user is bash-x.xx$.
 Root user default prompt is bash-x.xx#.

(b) Describe Windows NT Architecture and File System in detail?


Answer: - Windows NT Architecture:- NTFS (NT file system; sometimes New Technology
File System) is the file system that the Windows NT operating system uses for storing and
retrieving files on a hard disk. NTFS is the Windows NT equivalent of the Windows 95 file
allocation table (FAT) and the OS/2 High Performance File System (HPFS). However, NTFS
offers a number of improvements over FAT and HPFS in terms of performance, extendibility,
and security. There are some features of NTFS:

 Use of a b-tree directory scheme to keep track of file clusters


 Information about a file's clusters and other data is stored with each
cluster, not just a governing table (as FAT is)
 Support for very large files (up to 2 to the 64th power or approximately 16
billion bytes in size)
 An access control list (ACL) that lets a server administrator control who
can access specific files
 Integrated file compression
 Support for names based on Unicode
 Support for long file names as well as "8 by 3" names
 Data security on both removable and fixed disks.
The architecture of Windows NT is highly modular, and consists of two main layers: a user
mode and a kernel mode. Programs and subsystems in user mode are limited in terms of what
system resources they have access to, while the kernel mode has unrestricted access to the
system memory and external devices. The kernels of the operating systems in this line are all
known as hybrid kernels - although it is worth noting that this term is disputed, with the claim
that the kernel is essentially a monolithic kernel that is structured somewhat like a microkernel.
The architecture is comprised of a hybrid kernel, Hardware Abstraction Layer (HAL), drivers,
and Executive, which all exist in kernel mode . The higher-level services are implemented by the
executive.

User mode:

The user mode is made up of subsystems which can pass I/O requests to the appropriate kernel
mode drivers via the I/O manager (which exists in kernel mode). Two subsystems make up the
user mode layer: the Environment subsystem and the Integral subsystem.

Kernel mode:

Kernel mode has full access to the hardware and system resources of the computer and runs code
in a protected memory area. It controls access to scheduling, thread prioritization, memory
management and the interaction with hardware. The kernel mode stops user mode services and
applications from accessing critical areas of the operating system that they should not have
access to as user mode processes ask the kernel mode to perform such operations on its behalf.

Executive

The Executive interfaces with all the user mode subsystems. It deals with I/O, object
management, security and process management.
Further executive subsystems are the following:

 I/O Manager: allows devices to communicate with user-mode subsystems. It translates


user-mode read and write commands in read or write IRPs which it passes to device
drivers.
 Security Reference Monitor (SRM): the primary authority for enforcing the security
rules of the security integral subsystem.
 IPC Manager: short for Inter-process Communication Manager, this manages the
communication between clients (the environment subsystem) and servers (components of
the Executive).
 Virtual Memory Manager: manages virtual memory, allowing Windows 2000 to use
the hard disk as a primary storage device.
 Process Manager: handles process and thread creation and termination
 PnP Manager: handles Plug and Play and supports device detection and installation at
boot time.
 Power Manager: the power manager deals with power events and generates power IRPs.
 The display system has been moved from user mode into the kernel mode as a device
driver contained in the file Win32k.sys. There are two components in this device
driverthe Window Manager and the GDI:
o Window Manager: responsible for drawing windows and menus.
o GDI: the Graphics Device Interface is responsible for tasks such as drawing lines
and curves, rendering fonts and handling palettes.

Kernel & kernel-mode drivers:

The kernel sits between the HAL and the Executive and provides multiprocessor
synchronization, thread and interrupt scheduling and dispatching, and trap handling and
exception dispatching. The kernel often interfaces with the process manager. The kernel is also
responsible for initializing device drivers at bootup that are necessary to get the operating system
up and running.

Hardware abstraction layer:

HAL, is a layer between the physical hardware of the computer and the rest of the operating
system. It was designed to hide differences in hardware and therefore provide a consistent
platform on which applications may run. The HAL includes hardware specific code that controls
I/O interfaces, interrupt controllers and multiple processors.

You might also like