You are on page 1of 20

5th Sem (Regular & Back)

OS & CS3009
(CSE/IT/CSSE/CSCE)

AUTUMN END SEMESTER EXAMINATION-2019


5th Semester B.Tech & B.Tech Dual Degree
OPERATING SYSTEM
CS3009
(For2017 & Previous Admitted Batches)
Time: 3 Hours Full Marks: 50/60
Answer any SIX questions.
Question paper consists of four sections-A, B, C, D.
Section A is compulsory.
Attempt minimum one question each from Sections B, C, D.
The figures in the margin indicate full marks.
Candidates are required to give their answers in their own words as far as practicable and all parts of a
question should be answered at one place only.

SECTION-A
1. [1  10]
(a) Write the actions taken by a kernel to context-switch between processes.
Ans:
The Actions taken by a kernel to context-switch between processes are:
The OS must save the status of current execution process into its PCB.
The scheduler is invoked to determine the next process to be executed.
Then the information related to the selected process is retrieved from its PCB
into the corresponding registers.
(b) What is the number of child processes created by the following code:
int i;
for(i=0; i<3; i++)
fork( );
fork( );
Ans:15
(c) A counting semaphore S is initialized to 10. Then 6 WAIT operations and 4
SIGNAL operations were completed on this semaphore. What would be the
resulting value of S?
Ans: 8
(d) Name two CPU scheduling policy where context-switching does not occur.
Ans:
1. First Come First Served 2. Shortest Job First
(e) A system is having 3 user processes P1, P2 and P3 where P1 requires 2 units of
resource R, P2 requires 3 units of resource R, P3 requires 4 units of resource R.
What is the minimum number of units of R that ensures no deadlock in the
system?
Ans:
7 no. resources
(f) Define Highest Response ratio Next scheduling policy with its advantage.
Ans:
Highest Response ratio Next scheduling policy :
1. Out of all the available processes, CPU is assigned to the process having highest
response ratio. Response Ratio (RR) for any process is calculated by using the
formula-
Response Ratio=(Waiting time+Burst time)/Burst_time
KIIT-DU/2019/SOT/Autumn End Semester Examination-2019 KIIT-DU/2019/SOT/Autumn End
Semester Examination-2019
2. In case of a tie, it is broken by FCFS Scheduling.
3. It operates only in non-preemptive mode.
Advantages:
It performs better than SJF Scheduling.
It not only favors the shorter jobs but also limits the waiting time of longer jobs
which avoids starvation.
(g) Write the difference between thread and process.
Ans:
Difference between Process and Thread:
S.N
O PROCESS THREAD
Process means any program is in Thread means segment of a
1. execution. process.
Process takes more time to Thread takes less time to
2. terminate. terminate.
3. It takes more time for creation. It takes less time for creation.
It also takes more time for It takes less time for context
4. context switching. switching.
(h) What is a safe state in deadlock detection?
Ans:
A state is safe if the system can allocate all resources requested by all processes
( up to their stated maximums) without entering a deadlock state.

More formally, a state is safe if there exists a safe sequence of processes { P1,
P2,….. Pn} such that all of the resource requests for Pi can be granted using the
resources currently allocated to Pi and all processes Pj where j<i.(i.e., if all the
processes prior to Pi finish and free up their resources, then Pi will be able to
finish also, using the resources that they have freed up.)
(i) Define latency and seek time with respect to disk I/O.
Ans:
Rotational delay or latency is the time it takes for the beginning of the required
sector to reach the head.
Seek time is the time required to move the disk arm to the required track.
(j) Describe the purpose of device driver.
Ans:
Device Drivers are the software through which, the kernel of a computer
communicates with different hardware, without having to go into the details of
how the hardware works. The purpose of device drivers is to allow smooth
functioning of the hardware for which it is created and to allow it to be used with
different operating systems.
SECTION-B
2. (a) What is meant by domain of protection? How is it implemented by the operating [4]
system?
Ans: (first part 1.5 & second part 2.5)
A protection domain specifies the resources that a process may access.
Each domain defines a set of objects and the types of operations that may be invoked
on each object. An access right is the ability to execute an operation on an object.

Domain protection implementation


Brief discussion on domain structure and explanation of ACCESS MATRIX.
(b) 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. [4]
How many page faults would occur for the Optimal replacement algorithm and LRU
with three frames assuming that all frames are initially empty?
KIIT-DU/2019/SOT/Autumn End Semester Examination-2019 KIIT-DU/2019/SOT/Autumn End
Semester Examination-2019
Ans: (2 marks for each algorithms, in each algorithm 1.5 for steps 0.5 for
number of page faults)

3. (a) Consider the following set of processes, with the length of the CPU-burst time given [4]
in milliseconds:
Process Burst time Arrival time
P0 3 0
P1 6 2
P2 4 4
P3 5 6
P4 2 8

The processes are assumed to have arrived in the order P1, P2, P3, P4, P5, all at time
0.
i. Draw Gantt charts illustrating the execution of these processes using shortest
remaining time first and Round Robin (quantum = 2ms) scheduling.
ii. What is the turnaround time and the waiting time of each process for each of the
scheduling algorithms in part a?
Ans: ( 1 mark each for Gantt of SRTF & RR, 0.5 mark each for calculation turn
around time & waiting time in SRTF and 0.5 mark each for calculation turn
around time & waiting time in RR )

KIIT-DU/2019/SOT/Autumn End Semester Examination-2019 KIIT-DU/2019/SOT/Autumn End


Semester Examination-2019
KIIT-DU/2019/SOT/Autumn End Semester Examination-2019 KIIT-DU/2019/SOT/Autumn End
Semester Examination-2019
(b) What information is stored in Process Control Block to support context switching [4]
between two processes? What are the different criteria based on which a scheduling
algorithm can be evaluated?
Ans: ( part-1 2 marks, part-2 2 marks )
The information stored in PCB is process state, process number, program counter, and
registers.
The CPU scheduling criteria are CPU utilization, throughput, turnaround time, waiting
time, and response time.

SECTION-C
4. (a) Explain 1st readers-writers problem and write its solution using semaphore. [4]
Ans: ( Explanation 1 mark, reader algorithm 2 marks, writer algorithm 1 mark )

KIIT-DU/2019/SOT/Autumn End Semester Examination-2019 KIIT-DU/2019/SOT/Autumn End


Semester Examination-2019
The first Readers-Writers problem requires that no reader be kept waiting unless a
writer has already obtained permission to use the shared object. No reader should wait
for the other readers to finish simply because a writer is waiting.
The semaphore rw_mutex is common to both reader and writer processes. The mutex
semaphore is used to ensure mutual exclusion when the variable read_count is
updated. The read_count variable keeps track of the processes that are currently
reading the object. The semaphore read_mutex functions as a mutual exclusion
semaphore for the writers. It is also used by the first or last reader that enters or exists
the critical section. This is not only used by the readers who enter or exit while other
readers are in the critical sections
The reader process share the following data structures
Semaphore rw_mutex=1
Semaphore mutex =1
int read count=0
Writer Process: Reader Process:
do{ do{
wait(rw_mutex); wait(mutex);
…… read_count++;
/* Writing is performed */ if(read_count==1)
…… wait(rw_mutex);
signal(rw_mutex); signal(mutex);
}while(true); ……
/*Raeding is performed */
……
wait(mutex);
read_count- -;
if(read_count==0)
signal(rw_mutex);
signal(mutex);
}while(true);

(b) If the virtual address space is represented by 32 bits, the page size is 4Kbyte, the size [4]
of the physical memory is 64Mbyte and only 2 bits are used as control bits, calculate
the size of the page table.
Ans: ( step marking decided by examiner )

KIIT-DU/2019/SOT/Autumn End Semester Examination-2019 KIIT-DU/2019/SOT/Autumn End


Semester Examination-2019
5. (a) Consider the following snapshot of a system. [4]
Process Allocation Max
A B C D A B C D
P0 0 0 1 2 0 0 1 2
P1 1 0 0 0 1 7 5 0
P2 1 3 5 4 2 3 5 6
P3 0 6 3 2 0 6 5 2
P4 0 0 1 4 0 6 5 6
Resource type A has 3 instances, B has 14 instances, C has 12 instances and D has 12
instances.
Answer the following questions using banker’s algorithm
i) What is the content of the Need matrix?
ii) Illustrate that the system is in a safe state by demonstrating an order in which
the processes may complete.
iii) If a request from process P4 arrives for (0,4,2,0) can the request be granted
immediately?
Ans: ( (i) 0.5 mark, (ii) 2 marks, (iii) 1.5 mark )

KIIT-DU/2019/SOT/Autumn End Semester Examination-2019 KIIT-DU/2019/SOT/Autumn End


Semester Examination-2019
KIIT-DU/2019/SOT/Autumn End Semester Examination-2019 KIIT-DU/2019/SOT/Autumn End
Semester Examination-2019
KIIT-DU/2019/SOT/Autumn End Semester Examination-2019 KIIT-DU/2019/SOT/Autumn End
Semester Examination-2019
(b) Demonstrate the deadlock recovery mechanism in details. [4]
Ans: ( Process Termination 2 marks, Resource preemption 2 marks )

There are two basic approaches to recovery from deadlock:


1. Terminate one or more processes involved in the deadlock
2. Preempt resources.
Process Termination
 Two basic approaches, both of which recover resources allocated to terminated
processes:
o Terminate all processes involved in the deadlock. This definitely solves the
deadlock, but at the expense of terminating more processes than would be
absolutely necessary.
o Terminate processes one by one until the deadlock is broken. This is more
conservative, but requires doing deadlock detection after each step.
 In the latter case there are many factors that can go into deciding which
processes to terminate next:
i. Process priorities.
ii. How long the process has been running, and how close it is to
finishing.
iii. How many and what type of resources is the process holding. ( Are
they easy to preempt and restore? )
iv. How many more resources does the process need to complete.
v. How many processes will need to be terminated
vi. Whether the process is interactive or batch.
vii. ( Whether or not the process has made non-restorable changes to any
resource. )
Resource Preemption
 When preempting resources to relieve deadlock, there are three important
issues to be addressed:
1. Selecting a victim - Deciding which resources to preempt from which
processes involves many of the same decision criteria outlined above.
KIIT-DU/2019/SOT/Autumn End Semester Examination-2019 KIIT-DU/2019/SOT/Autumn End
Semester Examination-2019
2. Rollback - Ideally one would like to roll back a preempted process to a
safe state prior to the point at which that resource was originally allocated
to the process. Unfortunately it can be difficult or impossible to determine
what such a safe state is, and so the only safe rollback is to roll back all
the way back to the beginning. ( I.e. abort the process and make it start
over. )
Starvation - How do you guarantee that a process won't starve because its resources
are constantly being preempted? One option would be to use a priority system, and
increase the priority of a process every time its resources get preempted. Eventually it
should get a high enough priority that it won't get preempted any more.

6. Write short notes on the following


(a) Thrashing [4]
Ans: ( 2 marks )
Every program divided into some pages. When a program need a page which is not in
RAM that is called page fault. Whenever a page fault happens, operating system will
try to fetch that page from secondary memory and try to swap it with one of the page
in RAM. This is called swapping. If this page fault and then swapping happening very
frequently at higher rate, then operating system has to spend more time to swap these
pages. This state is called thrashing.
Thrashing is a condition or a situation when the system is spending a major portion of
its time in servicing the page faults, but the actual processing done is very negligible.

Thrashing is caused by under allocation of the minimum number of pages required by


a process, forcing it to continuously page fault. The system can detect thrashing by
evaluating the level of CPU utilization as compared to the level of multiprogramming.
It can be eliminated by reducing the level of multiprogramming.

Methods to handle thrashing:- Various methods to handle thrashing:


1. The OS attempts to recover from thrashing by suspending the execution of current
processes and preventing the execution of new process to start.
2. Thrashing can be removed by selecting an appropriate page replacement algorithm.
3. Thrashing can be avoided by using local page replacement algorithm. With local
replacement; the process cannot take frames from another process. It just selects
and swaps the page which belongs to the same process.
Thrashing can also be prevented by allocating a process as many frames as it needs.
(b) I-node [4]
Ans: ( 2 marks )

I-node is a data structure that keeps track of all the information about a file. We keep
our information in a file and the OS stores the information about a file in an I-node.
Data structures that contain information about files in UNIX file systems that are
created when a file system is created. Each file has an I-node and is identified by an I-
node number (I-number) in the file system where it resides. I-nodes provide important
information on files such as user and group ownership, access mode (read, write,
KIIT-DU/2019/SOT/Autumn End Semester Examination-2019 KIIT-DU/2019/SOT/Autumn End
Semester Examination-2019
execute permissions) and type.
The I-node contains the following pieces of information:
• Mode/permission (protection)
• Owner ID
• Group ID
• Size of file
• Number of hard links to the file
• Time last accessed
• Time last modified
• Time I-node last modified

When a file is created inside a directory then the file-name and I-node number are
assigned to file. These two entries are associated with every file in a directory. The
user might think that the directory contains the complete file and all the extra
information related to it but this might not be the case always. So we see that a
directory associates a file name with its I-node number.
When a user tries to access the file or any information related to the file then he/she
uses the file name to do so but internally the file-name is first mapped with its I-node
number stored in a table. Then through that I-node number the corresponding I-
node is accessed. There is a table (I-node table) where this mapping of I-node
numbers with the respective I-nodes is provided.
SECTION-D
7.
(a) Explain various File allocation methods and compare them with respect to space and [4]
time.
Ans: ( Description of three file allocation methods 1 mark each, comparison 1
mark )

The allocation methods define how the files are stored in the disk blocks. There are
three main disk space or file allocation methods.
1. Contiguous Allocation
2. Linked Allocation
3. Indexed Allocation
The main idea behind these methods is to provide:
 Efficient disk space utilization.
 Fast access to the file blocks.
All the three methods have their own advantages and disadvantages as discussed
below:
Contiguous Allocation
In this scheme, each file occupies a contiguous set of blocks on the disk. For
example, if a file requires n blocks and is given a block b as the starting location, then
the blocks assigned to the file will be: b, b+1, b+2,……b+n-1. This means that given
the starting block address and the length of the file (in terms of blocks required), we
KIIT-DU/2019/SOT/Autumn End Semester Examination-2019 KIIT-DU/2019/SOT/Autumn End
Semester Examination-2019
can determine the blocks occupied by the file.
The directory entry for a file with contiguous allocation contains address of starting
block and Length of the allocated portion. The file ‘mail’ in the following figure starts
from the block 19 with length = 6 blocks. Therefore, it occupies 19, 20, 21, 22, 23,
24 blocks.

Advantages:
 Both the Sequential and Direct Accesses are supported by this. For direct access,
the address of the kth block of the file which starts at block b can easily be obtained
as (b+k).
 This is extremely fast since the number of seeks are minimal because of contiguous
allocation of file blocks.
Disadvantages:
 This method suffers from both internal and external fragmentation. This makes it
inefficient in terms of memory utilization.
 Increasing file size is difficult because it depends on the availability of contiguous
memory at a particular instance.

2. Linked List Allocation


In this scheme, each file is a linked list of disk blocks which need not be contiguous.
The disk blocks can be scattered anywhere on the disk. The directory entry contains a
pointer to the starting and the ending file block. Each block contains a pointer to the
next block occupied by the file. The file ‘jeep’ in following image shows how the
blocks are randomly distributed. The last block (25) contains -1 indicating a null
pointer and does not point to any other block.

Advantages:

 This is very flexible in terms of file size. File size can be increased easily since the
system does not have to look for a contiguous chunk of memory.
 This method does not suffer from external fragmentation. This makes it relatively
better in terms of memory utilization.
Disadvantages:
 Because the file blocks are distributed randomly on the disk, a large number of
KIIT-DU/2019/SOT/Autumn End Semester Examination-2019 KIIT-DU/2019/SOT/Autumn End
Semester Examination-2019
seeks are needed to access every block individually. This makes linked allocation
slower.
 It does not support random or direct access. We can’t directly access the blocks of a
file. A block k of a file can be accessed by traversing k blocks sequentially
(sequential access) from the starting block of the file via block pointers.
 Pointers required in the linked allocation incur some extra overhead.

3. Indexed Allocation
In this scheme, a special block known as the Index block contains the pointers to all
the blocks occupied by a file. Each file has its own index block. The ith entry in the
index block contains the disk address of the ith file block. The directory entry contains
the address of the index block as shown in the image:
Advantages:
 This supports direct access to the blocks occupied by the file and therefore provides
fast access to the file blocks.
 It overcomes the problem of external fragmentation.
Disadvantages:
 The pointer overhead for indexed allocation is greater than linked allocation.
 For very small files, say files that expand only 2-3 blocks, the indexed allocation
would keep one entire block (index block) for the pointers which is inefficient in
terms of memory utilization. However, in linked allocation we lose the space of
only 1 pointer per block.

(b) Consider a disk system with 3000 cylinders, numbered 0 to 2999. The drive is [4]
currently serving a request at cylinder 143, and the previous request was at cylinder
125. The requests to access the cylinders occur in the following sequence:
86, 1470, 913, 1774, 948, 1509, 1022, 1750, 130.

Starting from the current head position, evaluate the time taken to satisfy all the
requests using shortest seek time first policy if it takes 1ms to move from one cylinder
to adjacent one? Also show the total head movement (in cylinders) for servicing the
request for C-SCAN and C-LOOK policy?

Ans:(SSTF with seek time calculation 2 marks, C-SCAN, C-LOOK 1 mark each )

KIIT-DU/2019/SOT/Autumn End Semester Examination-2019 KIIT-DU/2019/SOT/Autumn End


Semester Examination-2019
KIIT-DU/2019/SOT/Autumn End Semester Examination-2019 KIIT-DU/2019/SOT/Autumn End
Semester Examination-2019
8.
(a) In the memory four partitions are there of size 4KB, 8KB, 20KB and 2KB (in order) [4]
respectively. Total 8 processes arrive at time 0 with memory request size( in Bytes)
and usage time (in ms) as given in the following table: Calculate the time at which
process P7 will be completed if the Best fit method is used for fixed sized partitioned
memory.
Req. P1 P2 P3 P4 P5 P6 P7
No
Req. 2K 14K 3K 6K 6K 10K 7K
Size
Usage 4 10 2 8 4 1 8
time

Ans: (Step marking decided by Examiner )

KIIT-DU/2019/SOT/Autumn End Semester Examination-2019 KIIT-DU/2019/SOT/Autumn End


Semester Examination-2019
(b) Illustrate the concept of segmentation memory management scheme in detail with [4]
diagram.

Ans: ( Step marking decided by Examiner )

Segmentation is a memory management technique in which each job is divided into


several segments of different sizes, one for each module that contains pieces that
perform related functions. Each segment is actually a different logical address space of
the program.When a process is to be executed, its corresponding segmentation are
loaded into non-contiguous memory though every segment is loaded into a contiguous
block of available memory.Segmentation memory management works very similar to
paging but here segments are of variable-length where as in paging pages are of fixed
size.A program segment contains the program's main function, utility functions, data
structures, and so on. The operating system maintains a segment map table for every
process and a list of free memory blocks along with segment numbers, their size and
corresponding memory locations in main memory. For each segment, the table stores
the starting address of the segment and the length of the segment. A reference to a
memory location includes a value that identifies a segment and an offset.

KIIT-DU/2019/SOT/Autumn End Semester Examination-2019 KIIT-DU/2019/SOT/Autumn End


Semester Examination-2019
KIIT-DU/2019/SOT/Autumn End Semester Examination-2019 KIIT-DU/2019/SOT/Autumn End
Semester Examination-2019
MAPPING OF QUESTIONS WITH COURSE OUTCOMES AND LEARNING LEVELS

The paper setter /Moderator will provide mapping of Question with Course Outcomes and learning levels in
the following format:

Course Name: Operating Systems


Course code: CS3009
Examination: Autumn End Semester Examination 2019

CO1 Able to understand the difference between different types of modern operating
systems, virtual machines and their structure of implementation and applications.

CO2 Able to understand the difference between process & thread, issues of scheduling of
user-level processes/threads and their issues & use of locks, semaphores, monitors for
synchronizing multiprogramming with multithreaded systems and implement them in
multithreaded programs.

CO3 Able to understand the concepts of deadlock in operating systems and how they can
be managed/avoided and implement them in multiprogramming system.

CO4 Able to understand the design and management concepts along with issues and
challenges of main memory, virtual memory and file system.

CO5 Able to understand the types of I/O management, disk scheduling, protection and
security problems faced by operating systems and how to minimize these problems.

CO6 Able to familiar with various types of operating systems such as Unix.

Rows may be added or deleted as necessary

Question number Course Outcome number Learning Level (Blooms taxonomy)


Section A
Q1a CO2 2
1b CO6 2
1c CO2 2
1d CO4 2
1e CO3 2
1f CO2 2
1g CO2 1
1h CO4 1
1i CO4 1
1j CO5 1
Section B
Q2a CO5 1
2b CO4 2
Q3a CO2 3
3b CO2 1, 2
Section C
Q4a CO2 3
4b CO4 3
Q5a CO3 4
5b CO3 3
Q6a CO4 4
KIIT-DU/2019/SOT/Autumn End Semester Examination-2019 KIIT-DU/2019/SOT/Autumn End
Semester Examination-2019
6b CO4 4
Section D
Q7a CO4 6
7b CO5 6
Q8a CO4 5
8b CO6 5
8c CO4 6

Biswajit Sahoo
Signature of Paper Moderator

KIIT-DU/2019/SOT/Autumn End Semester Examination-2019 KIIT-DU/2019/SOT/Autumn End


Semester Examination-2019

You might also like