os assign question with solution
TRANSCRIPT
-
8/7/2019 OS Assign Question with Solution
1/13
Operating System Assignment
1. Define the Operating System?
Answer:An operating system is a program that manages the software applications and the working of computer
hardware. It also provides a basis for application programs and acts as an intermediary between a user of a computer
and the computer hardware.
2. What are various main functions of OS?
Answer: Major functions of OS:
Figure: Main Functions of an OS
Process Management:OS manages the processes (which are submitted to a computer system) in a manner tominimize idle time of processors (CPUs, I/O processors, etc.) of the system. Following working is the part of
process management:
Create, execute, delete process
Cancel or resume process, schedule process
Synchronization,
Communication,
Deadlock handling
Memory Management: Memory is important resource of a computer system that must be properly managedfor the overall system performance. Following working is the part of memory management:
Keeps the track of parts of memory in use and parts not in use
Allocates(provides) memory to processes as needed and de-allocates when no longer needed
File Management: File management module of an operating system takes care of file related activities such as:
Structuring(type of the file),
Accessing,
Naming,
Sharing,
1
-
8/7/2019 OS Assign Question with Solution
2/13
and protection of files
Device Management: OS manages and controls devices attached to computer. It handles devices by bothhardware and software techniques:
I/O Hardware: Ports, buses, device controllers for devices
Software (Device driver): OS communicates with I/O hardware via device driver of device
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, andcryptography 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 thecomputer 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.
3. Describe the structure of Process Control Block (PCB).Answer: Each process is represented in the operating system by a process control block(PCB) also called a task
control block. A PCB contains many pieces of information associated with a specific process, including these:
process state, program counter, CPU registers, CPU Scheduling information, Memory management information,
Accounting information, I/O status information.
Information associated with each process is stored in a Process Control Block (PCB), including:
process state (e.g., ready, running, waiting, )
program counter (address of next instruction to be executed)
CPU registers (active data stored in registers)
CPU scheduling info (process priority, pointers to scheduling queues, )
memory-management info (base & limit registers, page tables, )
accounting info (CPU time used, time limits, )
I/O status info (allocated I/O devices, open files, )
4. What you understand about Context Switching
(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
Figure: Process Control Block
-
8/7/2019 OS Assign Question with Solution
3/13
Figure: CPU Switch From Process to Process5. 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 processestrying to execute this portion must wait until the first process finishes.
6. How the CPU utilization is enhanced using:
a) Buffering, b) Multiprogrammi
ng,
c) Time
Sharing
Answer:
Buffering: CPU utilization is improved by using buffering mechanism for the CPU. Buffering uses memory to
compensate for the difference between the higher speed processor and lower speed disk or other device. In the case of
an output buffer, the output of a single job is sent to the buffer at high speed instead of directly to the slower output
device. Then, while the processor can continue with the execution of the job, the output device can read data from the
buffer and output that data synchronously, at a lower speed.
Multiprogramming: Multiprogramming increases CPU utilization by organizing jobs so that the CPU always has
productive work to do. If memory can hold several programs, then multiprogramming allows the processor to execute
another program while one program must wait for an I/O device.
3
-
8/7/2019 OS Assign Question with Solution
4/13
Time Sharing: A time-sharing system would offer the following benefits:
sharing of resources including devices (printer, disk), data and software;
greater safety (e.g., from viruses);
enhanced security and protection;
and provision of backups of data and software by a central site.
7. What you understand about Bounded Buffer producer-consumer problem? How such problem can be solve.
Answer: The producer-consumer problem (also known as the bounded-buffer problem) is a classical example of a
multi-process synchronization problem. The problem describes two processes, the producer and the consumer, who
share a common, fixed-size buffer. The producer's job is to generate a piece of data, put it into the buffer and startagain. At the same time the consumer is consuming the data (i.e. removing it from the buffer) one piece at a time. The
problem is to make sure that the producer won't try to add data into the buffer if it's full and that the consumer won't
try to remove data from an empty buffer.
The solution for the producer is to go to sleep if the buffer is full. The next time the consumer removes an item from
the buffer, it wakes up the producer who starts to fill the buffer again. In the same way the consumer goes to sleep if
it finds the buffer to be empty. The next time the producer puts data into the buffer, it wakes up the sleeping
consumer. The solution can be reached by means of inter-process communication, typically using semaphores. An
inadequate solution could result in a deadlock where both processes are waiting to be awakened.
4
-
8/7/2019 OS Assign Question with Solution
5/13
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
attributesDevice 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 offorkandexecve Unix System call
forksystem 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.
9. Differentiate the Multiprocessing versus multithreading.
Answer:
Multiprocessingrefers to the utilization of multiple CPUs in a single computer system. This is also called parallel
processing. It is also refers to a computer system's ability to support more than one process (program) at the same
time. Multiprocessing operating systems enable several programs to run concurrently. UNIX is one of the most
widely used multiprocessing systems, but there are many others, including OS/2 for high-end PCs. Multiprocessing
systems are much more complicated than single-process systems because the operating system must allocate
resources to competing processes in a reasonable manner. While,
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.
10. Define the role of Semaphore?
Answer:
Semaphores: Semaphore is a synchronization tool that is used to solve critical section problem. Semaphore S isinteger variable (counting semaphore) that can only be accessed via two indivisible (atomic) operations: wait and
signal. Semaphores when used incorrectly may cause Deadlocks and Starvation.
There are two types of semaphores:
5
-
8/7/2019 OS Assign Question with Solution
6/13
Counting semaphore Counting semaphore is a semaphore with an integer value that can range over
unrestricted domain.
Binary semaphore Binary semaphore is a semaphore with an integer value that can range only
between 0 and 1. They are more efficient to implement than counting semaphores.
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 timeProcess 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
13. What are the necessary conditions for deadlocks to occur?
Answer: Deadlocks occur if four conditions hold simultaneously. (All four must hold)
Mutual exclusion : only one process at a time can use a resource.
Hold and wait : a process holding at least one resource is waiting to acquire additional resources held by
other processes.
No pre-emption : a resource can be released only voluntarily by the process holding it, after that process
has completed its task.
Circular wait : there exists a set {P0, P1, ..., Pn } of waiting processes such that P0 is waiting for a
resource that is held by P1, P1 is waiting for a resource that is held by P 2, ..., Pn-1 is waiting for a resource
that is held by Pn, and Pn is waiting for a resource that is held by P0.
14. What you understand about starvation?
Answer: Starvation is indefinite blocking. A situation where processes wait indefinitely within a semaphore. A
process may never be removed from the semaphore queue in which it is suspended.
15. What is Deadlock Prevention?
Answer: Deadlock prevention is a technique which influences the design of the resources allocated and their
classification. It uses various techniques to ensure that at least one of the four necessary conditions for a deadlock is
violated. Thus, it eliminates the possibility of a deadlock ever occurring, in the design stage itself.
Deadlock prevention is a safe but pessimistic approach that involves no extra cost at runtime, but may be more
restrictive than necessary. That is, there could be allocations which might otherwise have been safe and led to
increased concurrency, but are ruled out due to the deadlock prevention design.
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.
6
-
8/7/2019 OS Assign Question with Solution
7/13
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
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 beplaced 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.
7
-
8/7/2019 OS Assign Question with Solution
8/13
Figure:Address Mapping in a Paging System
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) Multiprogrammi
ng with a fixed
number of processes
b) Multiprogrammi
ng with a variable
number of processes
c) Pa
ging
d) Segmenta
tion
Answer: The answer is:
a. Region sizes must be fixed in increments of 2k bytes, allocate key with memory blocks.
b. Same as above.
c. Frame sizes must be in increments of 2k bytes, allocate key with pages.d. Segment sizes must be in increments of 2k bytes, allocate key with segments.
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. Ifthere is free frameRead 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
8
-
8/7/2019 OS Assign Question with Solution
9/13
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
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.
22.Why page size is always powers of 2?
Answer: As we know that paging is implemented by breaking up an address into a page and offset number. It is most
efficient to break the address into X page bits and Y offset bits, rather than perform arithmetic on the address to
calculate the page number and offset. Because each bit position represents a power of 2, splitting an address betweenbits results in a page size that is a power of 2.
23.Assume the following page reference string:
1, 2, 3, 4, 2, 1, 5, 6, 2, 1, 2, 3, 7, 6, 3, 2, 1, 2, 3, 6.
How many page faults would occur for LRU replacement algorithm, assuming one, two, three and four
frames? Remember all frames are initially empty, so your first unique pages will all cost one fault each.
Answer: The answer is:
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
9
-
8/7/2019 OS Assign Question with Solution
10/13
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.
10
-
8/7/2019 OS Assign Question with Solution
11/13
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:
Figure: Six Step Process to Perform DMA Transfer
26. How Memory mapped I/O is different from DMA?
Answer: Memory-mapped I/O is a programming technique in which specific storage locations in main memory are
reserved for input or output devices. Memory-mapped I/O uses the same address bus to address both memory and I/Odevices, and the CPU instructions used to access the memory are also used for accessing devices. In order to
accommodate the I/O devices, areas of CPU's addressable space must be reserved for I/O rather than memory.
Direct memory access (DMA) is a feature of modern computers that allows certain hardware subsystems within
the computer to access system memory for reading and/or writing independently of the central processing unit. Many
hardware systems use DMA including disk drive controllers, graphics cards, network cards, and sound cards.
Computers that have DMA channels can transfer data to and from devices with much less CPU overhead than
computers without a DMA channel. With DMA, the CPU would initiate the transfer, do other operations while the
transfer is in progress, and receive an interrupt from the DMA controller once the operation has been done.
A device's direct memory access (DMA) is not affected by those CPU-to-device communication methods,especially it is not affected by memory mapping. This is because, by definition, DMA is a memory-to-device
communication method, which bypasses the CPU.
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
11
-
8/7/2019 OS Assign Question with Solution
12/13
control bus (rather than the data bus). The interrupt causes control to be transferred to the interrupt handler (a
system routine).
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 OwnerPassword 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
Create a new file of size zero (no data)
Unix commands: creat(2), open(2), mknod(8)
The attributes are set by the environment in which the file is created, e.g.
umask(1)
delete Delete an existing file Some systems may automatically delete a file that has not been used in n days
open
Establish a logical connection between process and file
Fetch the attributes and list of disk addresses into main memory for rapid access
during subsequent calls
close
Disconnects file from the current process
file not accessible to the process after close
I/O devices detached instead of closed
read
Transfer the logical record starting at current position in file to memory starting at
buffer (input buffer)
Older systems have a read_seq to achieve the same effect and read_direct forrandom access files
write
Transfer the memory (starting at buffer) to logical record (starting at current
position in file)
If current position is the end of file, filesize may increase
If current position is in the middle of file , some records may be overwritten and
lost
Older systems have a write_seq to achieve the same effect and write_direct for
random access files
append Restrictive form of write
seek Primarily used for random access files
Repositions the pointer to a specific place in file
get attributes Get information about the file
set attributes Set the attributes of a file, e.g., protection, access time
rename Change the name of a file
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 systemsin 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.
12
-
8/7/2019 OS Assign Question with Solution
13/13
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.
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.
30.What are threats? Describe the security roles in brief.
Answer: The major security threats perceived by users and providers of computer based systems include:
1. Unauthorized disclosure of information
2. Unauthorized alteration or destruction of information
3. Unauthorized use of service
4. Denial of service to legitimate users
Disclosure of information to unauthorized parties can result in breach of privacy and in both tangible and
intangible losses to the owner of the information. Revelation of a credit card number, a proprietary product
design, a list of customers, a bid on a contract, or strategic military data can be used by adversaries in numerousways. Depending on the nature of the information in question, the consequences of abuse can range from
inconvenience, to catastrophic losses.
Role of computer security
In principle, the role of computer security is to guard against and eliminate potential threats. In particular, a
secure system should maintain the integrity, availability, and privacy of data. That is, the data maintained by the
system should be correct, available, and private. As far as security is concerned, data integrity usually means:
1. Protection from unauthorized modification
2. Resistance to penetration
3. Protection from undetected modification of data
13