Operating System Top 10 Question with Answer Interviewer can ask (Randomly)
Que. What is deadlock? Discuss the necessary condition for deadlock.
Ans. Deadlock is a situation where a set of processes are blocked because each process is holding a resources acquired by some other process.
The necessary condition for deadlock are as follows:
- Mutual Exclusion: One or more than one resource are non-shareable (only one process can use at a time). For ex, Printer is an example of a resource that can be used by only one process at a time.
- Hold and Wait: There must exist a process which holds some resources and wait for another resource held by some other process. OR – A process holding at least one resource is waiting to acquire additional resources held by other processes.
- No Preemption: Resources cannot be preempted; that means a resource cannot be forcefully de-allocated and it can be released only by the process voluntarily after completing it’s task.
- Circular Wait: If the process are waiting for resources in a circle. For eg., P1 is holding resource R1 and waiting for resource R2 . Similarly, P2 holding resource R2 and waiting for resource R1 as represented then it leads to a deadlock.
Que. Describe Banker’s algorithm for Safe allocation.
Ans. The Banker’s algorithm is a resource allocation and deadlock avoidance algorithm that test for safety by simulating the allocation for predetermined maximum possible amounts of all resources , then makes an “s-state” check to test for possible activities , before deciding whether allocation should be allowed to continue…
- Multiple instances
- Each process must a priority claim maximum use
- When a process gets request a resources it may have to wait
- When a process gets all it’s resources it must return them in a finite amount of time
Que. Describe Safety Algorithm.
Ans. The algorithm for finding out whether or not a system is in safe state can be described as follows:
- Let Work and Finish be vector of length ‘m’ and ‘n’ respectively. Initialize: Work=Available Finish[i]=false; for i = 1,2,3,4,….,n
- Find an i such that both a) Finish[i]=False b) Need i <= Work if no such i exists go to step 4
- Work = Work + Allocation [i] ; Finish[i]= True go to step (2)
- If Finish[i]= true for all i ; then the system is in safe state
Que. Discuss the usage of wait-for-graph method.
Ans. Wait-for-graph is one of the method for detecting the deadlock situation . This method is suitable for smaller database .
In this method a graph is drawn based on the transaction and their lock on the resource. If the graph is created has a closed loop or a cycle, then there is a deadlock.
A wait-for-graph (WFG) is a graph where
- Each node represents a process;
- An edge , Pi–<Pj means that Pi is blocked waiting for Pj to reduce a resources.