0% found this document useful (0 votes)
3 views4 pages

Assigment

A deadlock occurs in operating systems when two or more processes cannot proceed because each is waiting for a resource held by another. The Banker's Algorithm is a method for deadlock avoidance by ensuring resource allocation keeps the system in a safe state. When prevention fails, deadlock detection and recovery mechanisms, such as resource allocation graphs and process termination, are necessary to resolve deadlocks.

Uploaded by

xbu029
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views4 pages

Assigment

A deadlock occurs in operating systems when two or more processes cannot proceed because each is waiting for a resource held by another. The Banker's Algorithm is a method for deadlock avoidance by ensuring resource allocation keeps the system in a safe state. When prevention fails, deadlock detection and recovery mechanisms, such as resource allocation graphs and process termination, are necessary to resolve deadlocks.

Uploaded by

xbu029
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

1. What is a Deadlock?

A deadlock is a condition in operating systems where two or more processes are unable to proceed
with execution because each is waiting for a resource held by another process. This leads to a state
where no process can continue.

Characteristics of Deadlock:

• Processes are blocked indefinitely.

• No process can finish its task.

• Resources remain allocated but unused.

Four Conditions Required for Deadlock:

1. Mutual Exclusion:

o Some resources can only be used by one process at a time.

o Example: Printers, files, and tape drives.

2. Hold and Wait:

o A process holds at least one resource and waits to acquire additional resources held
by other processes.

o Example: Process A holds Resource 1 and waits for Resource 2, which is held by
Process B.

3. No Preemption:

o Resources cannot be taken forcibly from a process; they must be released


voluntarily.

o Example: Once a printer is allocated to a process, it cannot be preempted until the


process is done.

4. Circular Wait:

o A circular chain of processes exists where each process holds a resource needed by
the next process.

o Example: Process A waits for B's resource, B waits for C's resource, and C waits for
A's resource.

Diagram of Deadlock (Circular Wait):

P1 --> R1

^ |

| v

R2 <-- P2

• P1 and P2 are processes.

• R1 and R2 are resources.


• Arrows show the hold and wait relationship.

2. Banker's Algorithm

The Banker's Algorithm is a deadlock avoidance algorithm that checks resource allocation before
granting requests to ensure the system remains in a safe state.

Important Terms:

• Available: Resources currently available in the system.

• Max: Maximum resources each process may request.

• Allocation: Resources currently allocated to each process.

• Need: Resources still required by each process.

Formula:

Need=Max−AllocationNeed = Max - Allocation

Steps in Banker's Algorithm:

1. Check Availability:

o Determine if the required resources are available.

o If yes, proceed to the next step.

2. Safety Sequence:

o Find a sequence where all processes can finish.

o If no safe sequence exists, the request is denied.

3. Resource Allocation:

o Allocate resources temporarily and perform the safety check.

o Finalize or roll back allocation based on the safety check.

Example:

Process Max (A B C) Allocation (A B C) Need (A B C)

P1 753 010 743

P2 322 200 122

P3 902 302 600

P4 222 101 121

P5 433 002 431

• Available: A=3, B=3, C=2


• Safe Sequence: P2 -> P4 -> P5 -> P1 -> P3

• Since a safe sequence exists, the system is in a safe state.

Diagram of Banker's Algorithm Workflow:

Request --> Available Resources --> Safety Check --> Safe State?

| |

No Yes

| |

Rollback Allocate

3. Deadlock Detection and Recovery

When deadlock prevention is not possible, systems implement mechanisms to detect and recover
from deadlocks.

Deadlock Detection:

1. Resource Allocation Graph (RAG):

o Nodes represent processes and resources.

o Edges represent allocation and request.

2. Cycle Detection:

o A cycle in the graph indicates the presence of a deadlock.

3. Detection Algorithm:

o Periodically run to check for cycles.

Diagram of Resource Allocation Graph:

P1 --> R1 --> P2

P2 --> R2 --> P3

P3 --> R3 --> P1

• The cycle indicates a deadlock.

Recovery from Deadlock:

1. Process Termination:

o Abort all deadlocked processes.

o Abort one process at a time until deadlock is resolved.

2. Resource Preemption:

o Reallocate resources by preempting from running processes.


o Consider factors like priority and execution time.

3. Rollback:

o Roll back to a safe checkpoint.

o Requires maintaining checkpoint logs.

Methods to Handle Deadlocks:

1. Deadlock Prevention:

o Break at least one of the four conditions.

2. Deadlock Avoidance:

o Use Banker's Algorithm.

3. Deadlock Detection:

o Detect cycles in the Resource Allocation Graph.

4. Deadlock Recovery:

o Abort processes or preempt resources.

Summary:

• Deadlocks halt system progress.

• Banker's Algorithm prevents unsafe resource allocation.

• Detection and recovery are essential when deadlocks are inevitable.

You might also like