Handling Deadlocks: Avoidance

To avoid deadlocks, the OS is required to know more information about each process, such as the number of available resources of each type and the maximum number of resources that a process could request during execution. Keeping track of this info leads to low device utilization.

When a scheduler sees that starting a process or granting resource requests may lead to future deadlocks, then that process is simply not run by the scheduler, or the request is not granted, a decision that avoids deadlocks.

A resource allocation state is a table containing the number of allocated resources, the number of available resources, and the number of maximum potentially required resources per each of the running processes.

A resource allocation state is called safe when the system can allocate all resources requested by all processes (up to their stated maximums) without entering a deadlock state. If a safe sequence does not exist, then the system is in an unsafe state, which may lead to deadlock. All safe states are deadlock free, but not all unsafe states lead to deadlocks.