0% found this document useful (0 votes)
28 views

OS Chapter 7 Simple Notes_072134

Os

Uploaded by

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

OS Chapter 7 Simple Notes_072134

Os

Uploaded by

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

Chapter 7: Deadlocks in Operating Systems

1. System Model

In an operating system, processes interact with various resources (like memory, CPU, I/O
devices). A deadlock happens when a set of processes are blocked because each process is
waiting for a resource that another process in the set is holding. Deadlocks are caused by
limitations in resources, imperfect inter-process communication, and restrictions on how
processes can access resources.

2. What is Deadlock?

Deadlock is a situation in which two or more processes cannot proceed because each is waiting
for resources held by the others. Essentially, the system reaches a state where no process can
continue its execution because of the waiting.

Deadlock occurs when:

 A process holds some resources and waits for others.


 Another process holds resources and waits for the first one, creating a cycle where no
process can proceed.

Example:

 Consider two tape drives and two processes, P1 and P2. If P1 holds one tape drive and
needs the other, and P2 holds the second one and also needs the first, neither process can
complete. This is a classic example of deadlock.

3. Deadlock Characteristics

A deadlock can arise when four conditions hold simultaneously:

1. Mutual Exclusion: Only one process can use a resource at a time (e.g., a printer).
2. Hold and Wait: A process holding one resource is waiting for another resource that is
currently held by another process.
3. No Preemption: Resources cannot be forcibly taken from a process once it holds them.
4. Circular Wait: A circular chain of processes exists, where each process is waiting for a
resource held by the next process in the chain.

4. Types of Resources

 Reusable Resources: These can be used by one process at a time but can be reused after
being released (e.g., CPU, memory).
 Consumable Resources: These are used and then destroyed by processes (e.g.,
messages, signals).
In a deadlock scenario, processes typically compete for reusable resources.

5. Starvation vs. Deadlock

 Starvation occurs when a process is indefinitely delayed in obtaining a resource because


other processes are always favored. This is different from deadlock because the process
may still be running, but it never gets the resource it needs.
 Deadlock involves processes that are permanently stuck, unable to proceed.

6. System Model in Deadlock

In a system, there are multiple resources and processes that request, hold, and release them. The
system’s state is defined by the resources available and the processes holding or requesting
resources.

7. Resource-Allocation Graph (RAG)

A Resource-Allocation Graph is used to represent processes, resources, and their interactions.


It shows:

 Request edges (from a process to a resource) indicating a process requesting a resource.


 Assignment edges (from a resource to a process) showing a resource allocated to a
process.

A cycle in the RAG suggests a potential deadlock, but a cycle alone isn't enough to confirm
deadlock—it depends on whether there is one instance or multiple instances of each resource
type.

8. Methods for Handling Deadlocks

There are three main methods for handling deadlocks:

1. Deadlock Prevention: Ensure that the system never enters a deadlock state by
disallowing one of the four deadlock conditions.
2. Deadlock Avoidance: Carefully allocate resources in a way that avoids situations where
deadlock could occur.
3. Deadlock Detection: Allow deadlocks to occur but periodically check for them and take
action to resolve the deadlock.

9. Deadlock Prevention

Deadlock prevention works by ensuring that at least one of the four conditions for deadlock is
not met. There are two ways to do this:

 Mutual Exclusion: This condition cannot be disallowed because certain resources like
printers must be used by only one process at a time.
 Hold and Wait: This can be prevented by ensuring that processes request all the
resources they will need before they begin execution.
 No Preemption: If a process holding some resources requests another resource, the
system can preempt the resources from the process and give them to others.
 Circular Wait: This can be prevented by imposing a strict ordering of resource requests,
so a process can only request resources in a predefined order.

10. Deadlock Avoidance

Deadlock avoidance involves dynamically checking resource allocation to ensure that a system
does not enter an unsafe state where deadlock might occur. There are two approaches to avoid
deadlocks:

1. Don’t start a process if it might lead to deadlock.


2. Don’t grant a resource request if it might lead to deadlock.

A safe state is one where a process can always finish by requesting resources in a way that
avoids deadlock.

The Banker's Algorithm is one method of deadlock avoidance. It works by checking if the
system can allocate resources without leading to a deadlock. The algorithm ensures that at any
point, there is a sequence of processes that can run to completion.

11. Deadlock Detection

In deadlock detection, the system is allowed to enter a deadlock state, but a detection algorithm
is periodically invoked to check if deadlock has occurred. This algorithm identifies the cycles in
the system that indicate a deadlock.

If there is only one instance of a resource type, a wait-for graph can be used to track which
processes are waiting for which others. A cycle in the graph indicates a deadlock.

12. Recovery from Deadlock

Once a deadlock is detected, the system must recover. There are two main strategies:

1. Process Termination: One or more processes involved in the deadlock are aborted. The
decision on which process to abort can be based on factors such as priority, resource
usage, or completion time.
2. Resource Preemption: Resources are preempted from processes involved in the
deadlock. This may involve rolling back processes to an earlier safe state.

Recovery might also involve starvation, where the same process may always be chosen as the
victim and never get a chance to proceed.

13. Combined Approach to Deadlock Handling


In some systems, a combined approach to deadlock handling is used, where prevention,
avoidance, and detection techniques are applied to different parts of the system depending on the
resources. This allows the system to handle deadlocks efficiently without overburdening one
approach.

14. The Dining Philosophers Problem

The Dining Philosophers Problem is a classic example used to illustrate the issues of deadlock,
starvation, and resource allocation. Five philosophers sit around a table, each with a plate of food
and a chopstick on each side. Each philosopher needs both chopsticks to eat. If all philosophers
pick up the left chopstick simultaneously, they will each wait forever for the right chopstick,
creating a deadlock.

Conclusion

Deadlocks are a significant problem in operating systems where resources are shared by
processes. By using techniques like deadlock prevention, avoidance, and detection, operating
systems ensure that processes can access resources efficiently without being stuck in deadlock
situations. Understanding the system model, resource allocation, and methods for handling
deadlocks is crucial for designing robust and efficient operating systems.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy