# Deadlock detection

## Definition

No deadlock-prevention or deadlock-avoidance is used.

* So, deadlock situations may occur.

The state of the system should be examined to determine whether a deadlock has occurred.

A recover from deadlock procedure should exist and be applied.

#### What to do?

* In a quite naive approach, the problem can simply be ignored.
* Otherwise, the circular chain of processes and resources need to be broken.

## Recover procedure

### How?

* **release resources from a process** – if it is possible
  * The process is suspended until the resource can be returned back.
  * Efficient but requires the possibility of saving the process state.
* **rollback** – if the states of execution of the different processes is periodically saved.
  * A resource is released from a process, whose state of execution is rolled back to the time the resource was assigned to it.
* **kill processes**
  * Radical but an easy to implement method.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://davidjosearaujo.gitbook.io/notes-miect/sistemas-de-operacao/deadlock/deadlock-detection.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
