Operating Systems: Deadlocks & Livelocks Flashcards

1
Q

What is deadlock in the context of operating systems?

A

Deadlock is a state where processes are unable to proceed because each holds at least one resource while waiting for another resource held by another process, leading to an indefinite standstill.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How does the dining philosophers problem illustrate the concept of deadlock?

A

In the dining philosophers problem, if all philosophers try to pick up the same pair of forks simultaneously, none can acquire both required resources, causing each to wait indefinitely—thus demonstrating deadlock.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How is deadlock formally defined?

A

Deadlock is formally defined as a situation where a group of processes becomes permanently blocked because each is holding resources and waiting for resources held by others, preventing any from making progress.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the four necessary conditions for deadlock to occur?

A

A deadlock occurs only if all the following conditions hold simultaneously: mutual exclusion, hold and wait, no pre-emption, and circular wait.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the role of the mutual exclusion condition in deadlock formation?

A

Mutual exclusion means that some resources are non-sharable, only one process can use a resource at a time. When a resource is occupied, any other process that requests it must wait until it is released.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What does the hold and wait condition describe?

A

Hold and wait occurs when a process holds one or more resources and simultaneously waits to acquire additional resources that are being held by other processes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How does the no pre-emption condition contribute to deadlock?

A

No pre-emption means that resources cannot be forcibly removed from a process; they can only be released voluntarily when the process has completed its task, allowing deadlock to persist.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is meant by the circular wait condition in deadlock scenarios?

A

Circular wait is when a set of processes forms a closed chain where each process is waiting for a resource held by the next process in the chain, creating a cycle that prevents any process from progressing.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Are the four conditions for deadlock independent? Explain.

A

Not completely; for instance, the circular wait condition inherently implies a hold and wait scenario. Nonetheless, in deadlock prevention strategies, each condition is treated as a separate constraint to control the occurrence of deadlock.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are the three primary strategies for handling deadlocks in operating systems?

A

The strategies are:
(1) ensuring the system never enters a deadlock state (prevention),

(2) allowing deadlocks to occur but providing mechanisms for detection and recovery, and

(3) ignoring deadlocks, assuming they are rare or manageable.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How do Resource Allocation Graphs (RAGs) assist in identifying deadlock states?

A

RAGs visually represent resource usage by depicting processes and resources as vertices and the relationships between them as directed edges (requests from processes to resources and assignments from resources to processes). They help identify deadlocks by revealing cycles within the graph.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are the types of vertices and edges in a Resource Allocation Graph (RAG)?

A

Vertices in a RAG are of two types: processes and resources. Edges also come in two forms: request edges (directed from a process to a resource) and assignment edges (directed from a resource to a process).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How is the usage of multiple instances of a resource represented in a RAG, and what does it imply for deadlock detection?

A

A RAG can show a resource type with several instances, where a process may request or hold one instance. When only one instance per resource exists, a cycle in the RAG confirms deadlock; with multiple instances, a cycle indicates the possibility of deadlock but does not definitively prove it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the procedure for using RAGs to determine the existence of a deadlock?

A

First, inspect the graph for cycles. If no cycle exists, then no deadlock is present. If a cycle exists and each resource type has only one instance, a deadlock is confirmed; if multiple instances are available, the cycle suggests the possibility of deadlock.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How can deadlock prevention be achieved by addressing the hold and wait condition?

A

Deadlock prevention can remove the hold and wait condition by ensuring that when a process requests a resource, it does not hold any others. This can be implemented by requiring processes to request and receive all needed resources before beginning execution.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What strategy can be used to counteract the no pre-emption condition in deadlock prevention?

A

A system can handle no pre-emption by requiring that if a process requests a resource that is not immediately available, it must release all currently held resources. This prevents processes from indefinitely holding resources while waiting for additional ones.

17
Q

How is circular wait prevented as a deadlock prevention measure?

A

Circular wait can be prevented by imposing a strict ordering on resource types so that all processes request resources in that predefined order. While this ordering helps avoid cycles, some circular waiting may still be essential for proper system operation.

18
Q

What distinguishes deadlock avoidance from deadlock prevention?

A

Deadlock avoidance does not restrict resource allocation outright; instead, it requires processes to declare their maximum resource needs in advance. The system then dynamically examines resource-allocation states before granting requests to ensure that the system remains in a safe state where deadlocks cannot occur.

19
Q

What conditions define a safe state in the context of deadlock avoidance?

A

A safe state exists if there is a sequence of process execution such that each process can eventually obtain its required resources, complete its execution, and release its resources. In other words, even if a process’s immediate needs aren’t met, the system can allocate resources in an order that guarantees eventual completion for all processes.

20
Q

How does the system verify whether a resource allocation leaves it in a safe state?

A

The system simulates the allocation to check if there is an order in which all processes can finish. If the sequence exists (e.g., processes waiting until previous ones complete and release resources), the allocation is safe; if not, it may lead to an unsafe state and potential deadlock.

21
Q

What is the role of the Banker’s Algorithm in deadlock avoidance for systems with multiple resource instances?

A

For systems with multiple instances of each resource, the Banker’s Algorithm is used to dynamically assess whether resource allocation requests can be safely granted. It checks if granting a request would leave the system in a safe state, thereby preventing the possibility of a deadlock.

22
Q

What is the primary idea behind deadlock detection and recovery?

A

Instead of attempting to prevent deadlocks, deadlock detection allows them to occur and then employs algorithms to identify and resolve the deadlock through recovery mechanisms, such as terminating processes or pre-empting resources.

23
Q

How does a Wait-For Graph simplify deadlock detection?

A

A Wait-For Graph is derived from a Resource Allocation Graph by including only the processes and the wait relationships between them. By focusing solely on processes waiting for resources, it simplifies the detection of cycles that indicate deadlocks.

24
Q

What factors should be considered when deciding how frequently to invoke a deadlock detection algorithm?

A

Key considerations include the computational overhead of running the algorithm, the likelihood of deadlock occurrences, and the potential cost of rolling back multiple processes. Frequent invocations may immediately identify deadlocks but can be resource-intensive, while infrequent checks might allow complex deadlock cycles to form.

25
What are the main approaches to recovering from a detected deadlock?
There are two primary recovery methods: terminating processes (either aborting all affected processes or selectively aborting some until the deadlock is resolved) and resource pre-emption (forcibly taking resources from processes, which may require rolling back process states and could lead to starvation).
26
What challenges arise with resource pre-emption as a deadlock recovery method?
Resource pre-emption involves determining which process to interrupt, how to safely rollback its state, and how to manage the potential for starvation of processes that might repeatedly lose resources.
27
What alternative approach do some operating systems take regarding deadlocks, and why?
Some operating systems, such as UNIX, choose to ignore deadlocks entirely. This approach is taken under the assumption that deadlocks are infrequent or manageable through manual intervention, thereby reducing the complexity and overhead of prevention, detection, and recovery mechanisms.
28
How is a livelock defined, and how does it differ from a deadlock?
A livelock occurs when processes continuously change their states in response to each other, yet none make meaningful progress toward completion. Unlike deadlock, where processes are blocked waiting for resources, in a livelock processes remain active but are stuck in an endless loop of state changes.
29
What resolution strategies are applicable to both deadlocks and livelocks?
Similar strategies, such as detection and recovery or redesigning resource management protocols, can be applied to both deadlocks and livelocks. In each case, the goal is to break the cycle of waiting or repetitive activity to allow processes to make progress.
30
What are the key objectives in the study of deadlocks and livelocks in operating systems?
The primary objectives include formalizing the definition of deadlocks, understanding and preventing their occurrence, exploring strategies for avoiding unsafe states, developing effective detection and recovery mechanisms, and distinguishing deadlock behavior from livelock scenarios.
31
What is the approach behind deadlock detection and recovery in operating systems?
Rather than designing the system to never enter a deadlock state, the approach allows deadlocks to occur but employs detection mechanisms to identify them and then applies recovery strategies. This method is relatively simple for systems with single resource instances and is extendable to multiple instances (refer to OSC Chapters 7.6–7.7).
32
What is a Wait-For Graph and how does it simplify deadlock detection?
A Wait-For Graph is derived from a Resource Allocation Graph by focusing only on processes and their waiting relationships. It simplifies deadlock detection by representing which processes are waiting for resources, allowing the system to periodically check for cycles that indicate deadlock.
33
When employing a deadlock detection algorithm, what factors must be considered, and what are the trade-offs?
Key factors include determining the optimal frequency for algorithm invocation, managing computational overhead, assessing how likely deadlocks are, and deciding the number of processes that might require rollback. Frequent checks offer prompt detection but incur high overhead, while infrequent checks risk multiple cycles forming and obscuring the original deadlock cause.
34
What are the primary alternatives for recovering from a deadlock once it is detected?
Recovery can be achieved by either terminating processes or pre-empting resources. Termination might involve aborting all affected processes or selectively aborting some until the deadlock is resolved, whereas resource pre-emption involves forcibly reallocating resources, though this approach may necessitate process rollback and could lead to starvation.
35
What challenges are associated with resource pre-emption as a strategy for deadlock recovery?
Resource pre-emption raises issues such as determining which process to interrupt, how to effectively rollback its state without data loss, and managing the risk of starvation for processes that might repeatedly be deprived of needed resources.
36
What is the alternative approach to handling deadlocks, and under what circumstances might it be used?
Some operating systems, notably UNIX, opt to ignore deadlocks entirely. This alternative relies on the assumption that deadlocks are rare or can be managed manually, although it is not suitable for environments where deadlocks could have critical consequences.
37
How are livelocks defined in the context of operating systems?
Livelocks occur when processes continuously change their state in response to each other without making any actual progress toward completion. Unlike deadlocks, where processes are completely blocked, livelocked processes remain active but are caught in an endless loop of ineffective actions.
38
How can the concept of livelock be illustrated with a real-world analogy?
Imagine two people walking in a narrow corridor who try to avoid colliding by stepping aside. If both mirror each other’s moves, stepping left, then right, then left again, they never actually pass one another. This scenario illustrates a livelock, where active behaviour prevents progress despite continual motion.