Os-2nd Batch PDF
Os-2nd Batch PDF
Section A (𝟐 × 𝟏𝟎 = 𝟐𝟎)
1. What is system calls? Explain the system call flow with the help of a block diagram.
A System call is a mechanism used by an application for requesting a service from the operating
system. Examples of the services provided by the operating system are allocation and
deallocation of memory, reporting of current date and time etc. These services can be used by an
application with the help of system calls. Many of the modern OS have hundreds of system calls.
For example Linux has 319 different system calls. Example: open, close, read, write, kill, wait
etc.
Fig: The 11 steps in making the system call read(id, buffer, nbytes)
System calls are performed in a series of steps. To make this concept clearer, let us examine the
read call. In preparation for calling the read library procedure, which actually makes the read
system call, the calling program first pushes the parameters onto the stack, as shown in steps 1-3
al
in figure. The first and third parameters are called by value, but the second parameter is passed
by reference, meaning that the address of the buffer (indicated by &) is passed, not the contents
ep
of the buffer. Then comes the actual call to the library procedure (step 4). This instruction is the
normal procedure call instruction used to call all procedures. The library procedure, possibly
itn
OR 1. What do you mean by file systems? What are the major difference between file
system interfaces and file system implementation? Explain.
We have three essential requirements for long-term information storage:
It must be possible to store a very large amount of information.
The information must survive the termination of the process using it.
Multiple processes must be able to access the information concurrently.
The usual solution to all these problems is to store information on disks and other external media
in units called files. Files are managed by the operating system. How they are structured, named,
accessed, used, protected, and implemented are major topics in operating system design. As a
whole, that part of the operating system dealing with files is known as the file system.
File system implementation deals with:
How files and directories are stored?
How disk space is managed?
How to make everything work efficiently and reliably?
The main objective of file system implementation is:
To describe the details of implementing local file systems and directory structures
To describe the implementation of remote file systems
To discuss block allocation and free-block algorithms and trade-offs
Different allocation methods are used in file system implementation. Some of the allocation
methods are:
al
Contiguous allocation
ep
Linked allocation
itn
File system interface provides applications with various system calls and commands such as
open, write, read, seek, etc. Since main memory is usually too small, the computer system
must provide secondary storage to back up main memory. The file system provides the
mechanism for storage of and (multiple) access to both data and programs residing on the
disks. Under this we describe following topics:
Access method
Directory structure
File system mounting
File sharing
Protection
Errors can also develop during normal operation after the drive has been installed. The first line
of defense upon getting an error that the ECC cannot handle is to just try the read again. Some
read errors are transient, that is, are caused by specks of dust under the head and will go away on
a second attempt, if the controller notices that it is getting repeated errors on a certain sector, it
can switch to a spare before the sector has died completely. In this way, no data are lost and the
operating system and user do not even notice the problem. Usually, the method of Fig (b) has to
be used since the other sectors might now contain data. Using the method of Fig (c) would
require not only rewriting the preambles, but copying all the data as well.
A hard disk consists of a stack of aluminum, alloy, or glass platters 5.25 inch or 3.5 inch in
diameter (or even smaller on notebook computers). On each platter is deposited a thin
magnetizable metal oxide. After manufacturing, there is no information whatsoever on the disk.
Before the disk can be used, each platter must receive a low-level format done by software. The
format consists of a series of concentric tracks, each containing some number of sectors, with
al
short gaps between the sectors. The format of a sector is shown in figure below:
ep
itn
File Operations:
Files exist to store information and allow it to be retrieved later. Different systems provide
different operations to allow storage and retrieval. Below is a discussion of the most common
system calls related to files:
Create: The file is created with no data. The purpose of the call is to announce that the
file is coming and to set some of the attributes.
Delete: When the file is no longer needed, it has to be deleted to free up disk space. There
is always a system call for this purpose.
Open: Before using a file, a process must open it. The purpose of the open call is to allow
the system to fetch the attributes and list of disk addresses into main memory for rapid
access on later calls.
Close: When all the accesses are finished, the attributes and disk addresses are no longer
needed, so the file should be closed to free up internal table space. Many systems
encourage this by imposing a maximum number of open files on processes. A disk is
written in blocks, and closing a file forces writing of the file’s last block, even though that
block may not be entirely full yet.
Read: Data are read from file. Usually, the bytes come from the current position. The
caller must specify how much data are needed and must also provide a buffer to put them
in.
Write: Data are written to the file, again, usually at the current position. If the current
position is the end of the file, the file’s size increases. If the current position is in the
middle of the file, existing data are overwritten and lost forever.
Append: This call is a restricted form of write. It can only add data to the end of the file.
Systems that provide a minimal set of system calls do not generally have append, but
many systems provide multiple ways of doing the same thing, and these systems
sometimes have append.
Seek: For random access files, a method is needed to specify from where to take the data.
One common approach is a system call, seek, that repositions the file pointer to a specific
place in the file. After this call has completed, data can be read from, or written to, that
position.
Get attributes: Processes often need to read file attributes to do their work. For example,
the UNIX make program is commonly used to manage software development projects
consisting of many source files. When make is called, it examines the modification times
of all the source and object files and arranges for the minimum number of compilations
required to bring everything up to date. To do its job, it must look at the attributes,
al
al
ep
itn
al
ep
itn
al
ep
itn
al
ep
itn
al
ep
itn
al
ep
itn
al
ep
itn
al
ep
itn
al
ep
itn
Number of frames Page faults for LRU Page faults for FIFO Page faults for Optimal
3 15 16 11
5 8 10 7
7 7 7 7
al
ep
itn
5. When do page fault occur? Describe the actions taken by an OS when a page fault
occurs?
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.
6. List four necessary conditions for deadlock. Explain each of them briefly what would be
necessary (in the operating system) to prevent the deadlock.
Deadlock can be defined formally as: A set of processes is deadlocked if each process in the set
is waiting for an event that only another process in the set can cause. Because all the processes
are waiting, none of them will ever cause any of the events that could wake up any of the other
members of the set, and all the processes continue to wait forever. Here below are the four
conditions which must be present for a deadlock to occur. If one of them is absent, no deadlock is
possible.
Mutual exclusion condition: Each resource is either currently assigned to exactly one
process or is available.
al
Hold and wait condition: Processes currently holding resources granted earlier can
request new resources.
ep
itn
of the operating system, without the process even knowing about them. Transition 2 occurs when
the scheduler decides that the running process has run long enough, and it is time to let another
ep
process have some CPU time. Transition 3 occurs when all the other processes have had their fair
itn
8. Does window have any concept of process hierarchy? How does parent control the child?
In some systems, when a process creates another process, the parent process and child process
continue to be associated in certain ways. The child process can itself create more processes,
forming a process hierarchy. Note that unlike plants and animals that use sexual reproduction, a
process has only one parent (but zero, one, two, or more children). Windows does not have any
concept of a process hierarchy. All processes are equal. The only place where there is something
like a process hierarchy is that when a process is created, the parent is given a special token
(called a handle) that it can use to control the child. However, it is free to pass this token to some
other process, thus invalidating the hierarchy.
In the operating system UNIX, every process except process 0 (the swapper) is created when
another process executes the fork () system call. The process that invoked fork is the parent
process and the newly-created process is the child process. Every process (except process 0) has
one parent process, but can have many child processes. The operating system kernel identifies
each process by its process identifier. Process 0 is a special process that is created when the
system boots; after forking a child process (process 1), process 0 becomes the swapper process
(sometimes also known as the "idle task"). Process 1, known as init, is the ancestor of every
other process in the system.
9. What is the problem with thread implementation in user space when any of the threads
get blocked while performing I/O operation?
Somewhat analogous to the problem of blocking system calls is the problem of page faults.
Computers can be set up in such a way that not all of the program is in main memory at once. If
the program calls or jumps to an instruction that is not in memory, a page fault occurs and the
operating system will go and get the missing instruction (and its neighbors) from disk. This is
called a page fault. The process is blocked while the necessary instruction is being located and
read in. If a thread causes a page fault, the kernel, not even knowing about the existence of
threads, naturally blocks the entire process until the disk I/O is complete, even though other
threads might be runnable.
al
The objective of multiprogramming is to have some process running all time, to maximize CPU
utilization. For this, the process scheduler selects an available process for execution on CPU
itn
11. What are the main motivations and issues in primary memory management?
The operating system must co-reside in main memory with one or more executing processes.
Memory management is responsible for allocating memory to processes and for protecting the
memory allocated to each process from undesired access b tither processes. It is also responsible
for protecting the memory allocated to the operating system from unauthorized access. Memory
management is not just a software task. The operating system requires hardware support to
implement any of the nontrivial memory management schemes. Thus, some operating system
design issues are also hardware design issues. Memory management hardware is typically
protected from user access; the operating system is solely responsible for its control.
The main issues in primary memory management are:
Single Partition
Absolute Single Partition
Relocatable Single Partition
Multiple Partition
Multiple Fixed Partition
Multiple Variable Partition
Partition Selection Algorithm
Disk Formatting
ep
Before a disk can store a data, it must be divided into sectors that the disk controller can read and
write, called low level formatting. The sector typically consists of preamble, data and ECC (error
itn
If disk I/O operations are limited to transferring the single sector at a time, it reads the first
sector from the disk and doing the ECC calculation, and transfers to main memory, during this
time the next sector will fly by the head. When transferring completes the controller will have to
wait almost an entire rotation for the second sector to come around again. This problem can be
eliminated by numbering the sectors in an interleaved fashion when formatting the disks.
According to copying rate, interleaving may be of single or double.
al
ep
itn