RTUComputer ScienceYr 2024 · Sem 52024

Q4Operating System

Question

4 marks

Discuss the methods of handling deadlock (prevention, avoidance, detection).

Answer

Deadlock can be handled through three main strategies: Prevention (eliminate necessary conditions), Avoidance (safe-state checking), and Detection & Recovery.

Deadlock handling methods fall into three categories:

Prevent at least one of the four Coffman conditions from holding: (a) Mutual Exclusion: Make resources sharable where possible (e.g., read-only files). Not always possible. (b) Hold and Wait: Require a process to request all resources before starting (low resource utilization) or release all resources before requesting new ones. (c) No Preemption: If a process requests a resource that cannot be immediately allocated, preempt all its currently held resources. (d) Circular Wait: Impose a total ordering on resource types and require processes to request in increasing order only.

Requires processes to declare maximum resource needs in advance. The system uses this information to ensure it never enters an unsafe state. The Banker's Algorithm checks whether granting a request will leave the system in a safe state (a state from which all processes can eventually complete). If unsafe, the request is denied.

Allow deadlocks to occur but detect and recover from them. Detection: Use a resource allocation graph (for single instance resources) or a detection algorithm similar to Banker's (for multiple instances). Recovery options: (a) Process Termination — abort all deadlocked processes, or abort one at a time until deadlock is broken. (b) Resource Preemption — preempt resources from some process and give them to others, then roll back the preempted process to a safe state.

Most modern OS (like Windows and Linux) ignore deadlocks (Ostrich Algorithm), relying on application-level handling, acceptable only when deadlocks are rare. Databases use deadlock detection and rollback.

Back to Paper