Operating System Important Question with Answer
Operating System Top 10 Question with Answer Interviewer can ask (Randomly)
Que. What is deadlock? Discuss the necessary condition for deadlock.
- 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.
- 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.
- Each node represents a process;
- An edge , Pi–<Pj means that Pi is blocked waiting for Pj to reduce a resources.