OS Assign Question With Solution
OS Assign Question With Solution
1
Protection and Security: Security deals with protecting the various resources and information of a computer
system against destruction and unauthorized access. It deals with user authentication, access control, and
cryptography mechanisms.
User authentication: Deals with the problem of verifying the identity of a user (person or program)
before permitting access to the requested resource.
Access Control: Once authenticated, access control mechanisms prohibit a user/process from accessing
those resources/information that he/she/it is not authorized to access.
Cryptography: Means of encrypting private information so that unauthorized access cannot use
information.
Back-up of data: Took the extra copy of essential data on another place of same or other storage device
or media.
Command Interpretation: It provides a set of commands using which the user can give instructions to the
computer to do some job. Two types of user interfaces (for command interpretation) supported by various
operating systems are:
Command-line interface(CLI): User gives instructions to the computer by typing the commands
(console mode).
Graphical User Interface (GUI): User gives commands to the system by selecting icon or menu item
displayed on the screen with the use of a point-and-draw device.
4. What you understand about Context Switching Figure: Process Control Block
(i) Answer: When CPU switches to another process, the system must save the state of the old process and load
the saved state for the new process. This task is called Context Switching.
2
5. What is Inter process Synchronization?
Answer:
Concurrent access to shared data may result in data inconsistency
Maintaining data consistency requires mechanisms to ensure the orderly execution of cooperating
processes
Inter Process synchronization (or serialization) is the application of particular mechanisms to ensure
that two or more than two concurrently-executing processes do not execute specific portions of a
program at the same time.
– If one process has begun to execute a serialized portion of the program, any remaining processes
trying to execute this portion must wait until the first process finishes.
3
8. Define System Calls and Interrupts.
Answer:
System Calls: System calls provide the interface between processes and the operating system. These calls are
usually available both from assembly-language programs and from higher-level language programs.
System calls can be roughly grouped into five major categories:
Process control: end, execute, wait, fork (create process), allocate and
free memory etc.
File manipulation: create/delete file, open/close, read/write, get/set
attributes
Device manipulation: request/release, read/write, get/set attributes
Information maintenance: get/set time/date, get process info.
Communications: create/delete connections, send/receive messages
Example: Use of fork and execve Unix System call
fork system call creates new process
execve system call used after a fork to replace the process’ memory space with a new program.
Interrupt: The hardware mechanism that enables a device to notify the CPU is known as interrupt. An
interrupt is generated by a hardware device, such as disk, which sends a signal to the control unit to indicate
the occurrence of some event (such as completion of an I/O request). The signal is sent through the control
bus (rather than the data bus). The interrupt causes control to be transferred to the interrupt handler (a system
routine).
Interrupt handler: It is a routine which determines the cause of the interrupt, performs the necessary
processing, and executes a return from interrupt instruction to return the CPU to the execution state prior
to the interrupt.
Interrupt controller: Interrupt controller is a hardware which performs the following function,
Defers interrupt handling
Dispatches proper interrupt handler
Issues multi-level interrupts.
Multithreading is the ability to perform different tasks of a process simultaneously. This is achieved by using a
separate thread for each task. Though there are several threads in a process, at a time the processor will handle only a
single thread. Though it appears to be concurrent processing to the end user, internally only single thread will be
running. Processor is able to multitask by switching between the threads. The programmer must carefully design the
program in such a way that all the threads can run at the same time without interfering with each other.
4
11. A CPU scheduling algorithm determines an order for the execution of its scheduled processes. Given ‘n’
processes to be scheduled on one processor, how many possible different schedules are there? Give a formula
in terms of ‘n’.
Answer: n! (n factorial = n × n – 1 × n – 2 × ... × 2 × 1).
12. There are three processes: P1, P2 and P3 which require the following CPU time
Process Burst time/Execution
time
P1 24
P2 4
P3 4
If we use a time-slice of 4 units of time, then what would be resultant if we use Round-robin scheduling
algorithm?
Answer: There are 3 processes: P1, P2 and P3 which require the following CPU time
Process Burst time/Execution time
P1 24
P2 4
P3 4
If we use a time-slice of 4 units of time, then P1 gets the first 4 units of time. Since it requires another 20
units of time, it is pre-empted after the first time slice and the CPU is given to the next process i.e. P2.
Since P2 just needs 4 units of time, it terminates as time-slice expires. The CPU is then given to the next
process P3. Once each process has received one time slice. The CPU is returned to P1 for an additional
time-slice. Thus the resulting round robin schedule is:
P1 P2 P3 P1
0 4 8 12 16 20 24 28 32
16. Assume that a system is in an unsafe state. Show that it is possible for the processes to complete their execution
without entering a deadlock state.
Answer: An unsafe state may not necessarily lead to deadlock; it just means that we cannot guarantee that deadlock
will not occur. Thus, it is possible that a system in an unsafe state may still allow all processes to complete without
deadlock occurring. Consider the situation where a system has 12 resources allocated among processes P0, P1, and
P2. The resources are allocated according to the following policy:
Max Current Need
P0 10 5 5
5
P1 4 2 2
P2 9 3 6
Currently there are two resources available. This system is in an unsafe state as process P1 could complete,
thereby freeing a total of four resources. But we cannot guarantee that processes P0 and P2 can complete. However, it
is possible that a process may release resources before requesting any further. For example, process P2 could release
a resource, thereby increasing the total number of resources to five. This allows process P0 to complete, which would
free a total of nine resources, thereby allowing process P2 to complete as well.
17. Differentiate the Contiguous and Non-Contiguous Memory Allocation.
Answer: Contiguous means it's all in one chunk, so from the start to the end there's nothing else in it. Non-
contiguous is the opposite, it means that the memory is fragmented and there are one or more sections that are
allocated to other processes.
In contiguous memory allocation, as the name implies, each program has to occupy a single contiguous
block of storage location.
In non contiguous storage allocation, a program is divided into several blocks or segment that may be
placed throughout main storage in pieces not necessarily adjacent to one another.
18. Define the paging and segmentation? Explain address mapping in paging system.
Answer:
PAGING: Paging is the OS mechanism it is done by splitting the program into a group of fixed-equal-sized
partitions, allowing the parts to be allocated as non-contiguous. Paging is a memory management technique that
permits a program's memory to be non-contiguous into physical memory thus allowing a program to be allocated
physical memory wherever it is possible. When a programmer wants to transfer a data from one location to another,
he might write for example: move R1 2000 (i.e. moving the content of memory address 2000 to register R1). Address
of memory location can be generated using indexing, base registers, segment registers and other ways. These
programs generated addresses are called logical addresses and form the logical address space. There has to be
mapping between logical address space and physical address space. Paging does such mapping.
SEGMENTATION: Segmentation is a memory management scheme, which supports programmers' view of
memory. Programmers never think of their programs as a linear array of words. Rather, they think of their programs
as a collection of logically related entities, such as subroutines or procedures, functions, global or local data areas,
stack etc. Segments are formed at program translation time by grouping together logically related entities. Formation
of these segments varies from one compiler to another. In segmented systems, components belonging to a single
segment reside in one contiguous area but different segments belonging to the same process occupy non-
contiguous area of physical memory because each segment is individually relocated.
ADDRESS MAPPING IN A PAGING SYSTEM: The physical memory is conceptually divided into a number of
fixed-size blocks called frames (or page frames). The virtual address space or logical memory of a process is also
broken into blocks of the same size called pages. When a program is to be run, its pages are loaded into any frame
from the disks. To reduce the access time, the use of registers can be considered if the number of entries in PMT
(Page map table) is quite small (around 256 entries). For keeping very large entries (around 1,000,000 entries), PMT
is usually kept in primary memory because the use of registers for keeping such a large number of entries is not
feasible.
6
Thus, PMT is usually kept in primary memory and there is a Page Table Base Register (PTBR) pointing to the
beginning of PMT. Problem with this approach is memory access time. Suppose we want to access a location L, we
first index into PMT by counting a base address of PMT (b) offset by page number (p) for that location i.e. b + p. his
task requires a memory access which in turn gives a frame number, which is combined with page offset to produce
actual address. With this scheme, two memory accesses are required (one for PMT and one for the data). Thus,
memory is slowed by a factor of two. Therefore, faster translation methods must be used. The standard solution to
this problem is to store the complete page map table into an associative memory also called look-aside memory or
content addressable memory.
19. Describe the following Memory Management methods by appropriate examples:
a) Multiprogramming b) Multiprogramming c) Paging d) Segmentation
with a fixed number with a variable
of processes number of processes
Answer:
20. What do you know about Page Replacement Concept in memory management? Explain one of the Page
replacement algorithms with suitable example.
Answer: This concept is concerned with which page need to be removed in order to provide space to the incoming
page, if the primary storage is already full.
For example: Web server. The server can keep a certain number of heavily used Web pages in its memory
cache. However, when the memory cache is full and a new page is referenced, a decision has to be made which
Web page to evict.
Steps involved in replacement of page:
1. Find the location of the desired page on the disk.
2. Find a free frame.
3. If there is free frame
Read the desired page into new free frame; change the page and frame tables.
Else, use a page- replacement algorithm to select a victim frame, write the victim page to the
disk; change the page and frame tables accordingly.
4. Restart the user process.
There are several algorithms available to replace the page.
1. Optimal Page Replacement Algorithm
2. FIFO Page Replacement Algorithm
3. LRU Page Replacement Algorithm
FIFO Page Replacement Algorithm: When a page must be replaced, the oldest page is chosen. Notice that it is not
strictly necessary to record the time when a page is brought in. we can create a FIFO queue to hold all pages in
memory. We replace the page at the head of the queue. When a page is brought in to memory, we insert it at the tail
of the queue.
Example: suppose 3 pages can be in memory at a time per process
process references pages: 7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 1, 2, 0, 1, 7, 0, 1
requires 15 page faults
21. When the page faults occur? Describe the actions taken by the operating system when a page fault occurs.
Answer: A page fault occurs when an access to a page that has not been brought into main memory takes place. The
operating system verifies the memory access, aborting the program if it is invalid. If it is valid, a free frame is located
7
and I/O is requested to read the needed page into the free frame. Upon completion of I/O, the process table and page
table are updated and the instruction is restarted.
24. Consider a logical address space of eight pages of 1024 words each, mapped onto a physical memory of 32
frames.
(i) How many bits are there in the logical address?
(ii) How many bits are there in the physical address?
Answer:
a. Logical address will have
3 bits to specify the page number (for 8 pages) .
10 bits to specify the offset into each page (210 =1024 words) = 13 bits.
b. For 32(or =25) frames of 1024 (or =210) words each (as we know Page size = Frame size)
We have 5 + 10 = 15 bits.
8
25. What you understand about DMA? Brief the working of DMA in steps with schematic diagram.
Answer: DMA is a method of transferring data from the computer's RAM to another part of the computer without
processing it using the CPU. While most data that is input or output from your computer is processed by the CPU, but
some data does not require processing, or can be processed by another device. In these situations, DMA can save
processing time and is a more efficient way to move data from the computer's memory to other devices.
Following is schematic diagram to show the working of six steps process to perform DMA transfer:
27. Explain the differences between Trap and an Interrupt with an example.
Answer: A trap is generated by a running process or user program that attempts an operation that is
considered abnormal; for example, a user program that attempts to divide by zero. It may also be generated by
a running process that issues a service request from the operating system; for example, a program that attempts
to access protected memory or execute a privileged instruction. A trap is similar to an interrupt, and causes
control to be transferred to an exception handler routine.
An interrupt is generated by a hardware device, such as disk, which sends a signal to the control unit to
indicate the occurrence of some event (such as completion of an I/O request). The signal is sent through the
control bus (rather than the data bus). The interrupt causes control to be transferred to the interrupt handler (a
system routine).
9
28. What are the various types of File attributes? Also describe the various file operations.
Answer: File Attributes are as follows:
Protection Flags: Read-only flag, Hidden file flag, System file flag, Archive flag,
ascii/binary flag, Random access flag, Temporary flag, Lock flag
Creator Owner
Password For security purpose
Key position Data about files
Key length Creation time
Time of last change last access time
Maximum size Current size
File operations: File treated as abstract data type, following operations can be possible on a file
– Create a new file of size zero (no data)
– Unix commands: creat(2), open(2), mknod(8)
create
– The attributes are set by the environment in which the file is created, e.g.
umask(1)
– Delete an existing file
delete
– Some systems may automatically delete a file that has not been used in n days
set attributes – Set the attributes of a file, e.g., protection, access time
29. Define File System. Discuss the fixed length or variable length records file access methods.
Answer: In a computer, a file system is the way in which files are named and where they are placed logically for
storage and retrieval. The DOS, Windows, OS/2, Macintosh, and UNIX-based operating systems all have file systems
in which files are placed somewhere in a hierarchical (tree) structure. A file is placed in a directory (folder in
Windows) or subdirectory at the desired place in the tree structure.
File systems specify conventions for naming files. These conventions include the maximum number of characters
in a name, which characters can be used, and, in some systems, how long the file name suffix can be. A file system
also includes a format for specifying the path to a file through the structure of directories.
10
Older Linux machines used a file system called ext2, while newer Linux computers use ext3. Earlier Windows
machines used a file system called FAT32, while newer Windows computers use NTFS. Macintosh computers used
the HFS file system for a long time, but now use an updated version of HFS, called HFS+. Though you typically don't
need to know all the details of your computer's file system, it is nice to know that it is always working to keep your
files organized.
Sequential Access: Information in the file is processed in order, one record after the other. This mode of
access is known as sequential access. It is one of the common and simple methods of access. For e.g. editors
and compilers access files in this fashion.
Random Access (Direct Access): A file is made up of fixed length logical records that allow programs to read and
write records rapidly in no particular order. It is based on the disk model of files, which allows random access.
11