Operating System deadlock top 10 viva questions
Top 10 Deadlock Viva Questions and Answers in Operating System
1. What is a deadlock in an operating system?
A deadlock is a situation in an operating system where two or more processes are unable to proceed because each is waiting for the other to release resources. This results in a complete standstill where no process can complete its execution.
2. What are the necessary conditions for a deadlock to occur?
Four necessary conditions must hold simultaneously for a deadlock to occur:
- Mutual Exclusion: At least one resource must be held in a non-shareable mode.
- Hold and Wait: A process holding one resource is waiting to acquire additional resources.
- No Preemption: Resources cannot be forcibly taken away from a process.
- Circular Wait: A set of processes are waiting for each other in a circular chain.
3. How can deadlocks be prevented?
Deadlocks can be prevented by ensuring that at least one of the necessary conditions does not hold. Techniques include resource ordering, preventing hold and wait by requesting all resources at once, or allowing resource preemption.
4. What is the difference between deadlock prevention and deadlock avoidance?
Deadlock Prevention eliminates the possibility of deadlocks by restricting how requests are made, while Deadlock Avoidance allows resource allocation but checks in advance if granting a resource may lead to a deadlock, using algorithms like the Banker's Algorithm.
5. What is the Banker's Algorithm?
The Banker's Algorithm is a deadlock avoidance algorithm that works like a bank lending system. Before allocating resources, it checks whether the system will remain in a safe state. If yes, the allocation is done; otherwise, it is delayed until it becomes safe.
6. What is a resource allocation graph (RAG)?
A Resource Allocation Graph is a graphical representation used to detect deadlocks. It consists of processes, resources, and edges showing allocation and request relations. A cycle in the graph indicates the possibility of a deadlock.
7. Can deadlocks be ignored?
In some systems, particularly where deadlocks are rare, it is acceptable to ignore deadlocks altogether. This approach is called the "Ostrich Algorithm" — pretending deadlocks do not exist, to avoid the overhead of prevention or detection mechanisms.
8. How does deadlock detection differ from deadlock prevention?
Deadlock Detection allows deadlocks to occur but detects them afterward, often using resource allocation graphs or matrices. Deadlock Prevention actively ensures that a deadlock cannot occur in the first place by breaking one or more necessary conditions.
9. What is a safe state in deadlock avoidance?
A system is in a safe state if there exists a sequence of process execution where every process can complete without getting into a deadlock. Deadlock avoidance algorithms ensure that the system remains in a safe state at all times.
10. Mention two real-life examples of deadlock situations.
Two common real-life examples are:
- Traffic Deadlock: Vehicles waiting at a crossroads where each car waits for the other to move first.
- Dining Philosophers Problem: Philosophers seated around a table needing two forks to eat, leading to deadlock when each picks one fork and waits for the other.
Comments
Post a Comment