Tuesday 25 September 2012

OS Interview Questions-5


1.What is critical section problem?
Ans: Critical section is the code segment of a process in which the process may be changing common variables, updating tables, writing a file and so on. Only one process is allowed to go into critical section at any given time (mutually exclusive).The critical section problem is to design a protocol that the processes can use to co-operate. The three basic requirements of critical section are:
1. Mutual exclusion
2. Progress
3. bounded waiting
Bakery algorithm is one of the solutions to CS problem.

2.What is a semaphore?
Ans: It is a synchronization tool used to solve complex critical section problems. A semaphore is an integer variable that, apart from initialization, is accessed only through two standard atomic operations: Wait and Signal.

3.What is bounded-buffer problem?
Ans: Here we assume that a pool consists of n buffers, each capable of holding one item. The semaphore provides mutual exclusion for accesses to the buffer pool and is initialized to the value 1.The empty and full semaphores count the number of empty and full buffers, respectively. Empty is initialized to n, and full is initialized to 0.

4.What is readers-writers problem?
Ans: Here we divide the processes into two types:
1. Readers (Who want to retrieve the data only)
2. Writers (Who want to retrieve as well as manipulate)
We can provide permission to a number of readers to read same data at same time.But a writer must be exclusively allowed to access. There are two solutions to this problem:
1. No reader will be kept waiting unless a writer has already obtained permission to use the shared object. In other words, no reader should wait for other readers to complete simply because a writer is waiting.
2. Once a writer is ready, that writer performs its write as soon as possible. In other words, if a writer is waiting to access the object, no new may start reading.

5.What is dining philosophers’ problem?
Ans: Consider 5 philosophers who spend their lives thinking and eating. The philosophers share a common circular table surrounded by 5 chairs, each belonging to one philosopher. In the center of the table is a bowl of rice, and the table is laid with five single chop sticks. When a philosopher thinks, she doesn’t interact with her colleagues.
From time to time, a philosopher gets hungry and tries to pick up two chop sticks that are closest to her .A philosopher may pick up only one chop stick at a time. Obviously she can’t pick the stick in some others hand. When a hungry philosopher has both her chopsticks at the same time, she eats without releasing her chopsticks. When she is finished eating, she puts down both of her chopsticks and start thinking again.

6.What is a deadlock?
Ans: Suppose a process request resources; if the resources are not available at that time the process enters into a wait state. A waiting process may never again change state, because the resources they have requested are held by some other waiting processes. This situation is called deadlock.

7.What are necessary conditions for dead lock?
Ans:
1. Mutual exclusion (where at least one resource is non-sharable)
2. Hold and wait (where a process hold one resource and waits for other resource)
3. No preemption (where the resources can’t be preempted)
4. circular wait (where p[i] is waiting for p[j] to release a resource. i= 1,2,…n
j=if (i!=n) then i+1 else 1 )

8.What is resource allocation graph?
Ans: This is the graphical description of deadlocks. This graph consists of a set of edges E and a set of vertices V. The set of vertices V is partitioned into two different types of nodes P={p1,p2,…,pn}, the set consisting of all the resources in the system, R={r1,r2,…rn}.
A directed edge Pi?Rj is called a request edge; a directed edge Rj?Pi is called an assignment edge. Pictorially we represent a process Pi as a circle, and each resource type Rj as square.Since resource type Rj may have more than one instance, we represent each such instance as a dot within the square.When a request is fulfilled the request edge is transformed into an assignment edge. When a process releases a resource the assignment edge is deleted. If the cycle involves a set of resource types, each of which has only a single instance, then a deadlock has occurred. Each process involved in the cycle is deadlock.

9.What are deadlock prevention techniques?
Ans:
1. Mutual exclusion : Some resources such as read only files shouldn’t be mutually exclusive. They should be sharable. But some resources such as printers must be mutually exclusive.
2. Hold and wait : To avoid this condition we have to ensure that if a process is requesting for a resource it should not hold any resources.
3. No preemption : If a process is holding some resources and requests another resource that cannot be immediately allocated to it (that is the process must wait), then all the resources currently being held are preempted(released autonomously).
4. Circular wait : the way to ensure that this condition never holds is to impose a total ordering of all the resource types, and to require that each process requests resources in an increasing order of enumeration.

10.What is a safe state and a safe sequence?
Ans: A system is in safe state only if there exists a safe sequence. A sequence of processes is a safe sequence for the current allocation state if, for each Pi, the resources that the Pi can still request can be satisfied by the currently available resources plus the resources held by all the Pj, with j

No comments:

Post a Comment