Problem Statement
How can an operating system prevent deadlock? Describe at least two techniques with trade-offs.
Explanation
An OS can prevent deadlock by ensuring at least one of the four necessary conditions never holds. Two common techniques are: 1) Resource ordering – assign a global ordering to resources and require all processes to request resources in that order, thereby avoiding circular wait. 2) Preemption – allow the OS to preempt a resource from a process (breaking the no-preemption condition). For example, if a process holds some resources and requests others and cannot get them, the OS may force it to release its held resources. The trade-offs: ordering can be rigid and complex for many resource types; preemption can lead to wasted work or inconsistent state if resources are forcibly removed. In interviews, stating trade-offs shows deeper understanding.
