Principles of Operating System Questions and Answers
Principles of Operating System Questions and Answers
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.
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.
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?
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:
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.
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:
Base Address: It contains the starting physical address where the segments reside in
memory.
Limit: It specifies the length of the segment.
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.
(ii) Optimal Page replacement:- In this algorithm, pages are replaced which would not be
used for the longest duration of time in the future.
(iii)Least Recently Used (LRU):- In this algorithm page will be replaced which is least
recently used.
Q4: What do you mean by file? Discuss different types of file access and file allocation
methods with suitable examples?
(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.
Disadvantage:
(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.
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:
(iv). The GNU Bourne-Again Shell: The GNU Bourne-Again shell (bash):
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:
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.
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.