deadlock avoidance
Imagine a careful bank manager who, before approving each loan, asks: 'If I grant this, could I still satisfy everyone's worst-case future demands and get all my money back?' If yes, approve; if it might back the bank into a corner, make the borrower wait. The manager never forbids loans outright (that would be prevention) — instead each request is checked against the future, and only requests that keep the bank safe are granted. Deadlock avoidance is exactly this cautious, request-by-request approach.
Avoidance assumes each process declares in advance the MAXIMUM number of each resource type it might ever need. With that knowledge, before granting any request the OS asks: would granting it leave the system in a SAFE STATE — one in which there exists at least one ordering of the processes such that each, in turn, can obtain its maximum needs, finish, and release, letting the next proceed? If granting keeps the system safe, allow it; if it would lead to an UNSAFE state (one with no such guaranteed completion order), make the requesting process wait, even though the resources are physically available right now. The banker's algorithm is the standard procedure that performs this safety check.
Avoidance is less restrictive than prevention because it allows requests prevention would forbid, granting them whenever the future still looks safe. But it is honestly demanding and rarely used in general-purpose operating systems. It requires every process to know and declare its maximum needs up front (often impossible), assumes a fixed number of processes and resources, and runs a safety check on every request, which is costly. Crucially, an unsafe state is NOT yet a deadlock — it is a state from which deadlock becomes possible; avoidance simply refuses to ever step into one.
Ten tape drives, three processes that may eventually need 7, 4, and 6 respectively. Even when a request could be granted physically, the OS grants it only if a safe sequence still exists (e.g. let the process needing 4 finish first, release, then serve the others). If no safe sequence remains, the request waits.
Avoidance grants a request only if the system stays in a safe state afterward.
Avoidance needs each process's maximum future needs declared in advance and a safety check on every request — usually impractical, so general-purpose OSes rarely use it. An unsafe state is not a deadlock, only a state from which one becomes possible.