Understanding Deadlock in Operating Systems

operating systems n.w
1 / 38
Embed
Share

Learn about the concept of deadlock in operating systems, where conflicting resource needs lead to processes being blocked, and explore the conditions that can cause deadlock to occur. Discover how deadlock is modeled and analyzed in computer systems to prevent these situations.

  • Deadlock
  • Operating Systems
  • Resource Allocation
  • System Modeling
  • Process Management

Uploaded on | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. Operating Systems Deadlock By: Rooa Khaled Uraybee SUPERVISER Dr. Sundoos AL-AZAWEE

  2. Introduction:- Generally speaking, deadlock, involves conflicting needs for resources by two or more request orders. A common example is ((a traffic deadlock)) A deadlock is a situation where a set of processes are blocked because each process is holding a resource and waiting for another resource acquired by some other process. Deadlock can occur via: System calls locking, etc ..

  3. Resources:- System consists of resources Resource types R1, R2, . . ., Rm CPU cycles, memory space, I/O devices Each resource type Ri has Wi instances Each process utilizes a resource as follows: request use release

  4. Deadlocks conditions Deadlock can arise if four conditions hold simultaneously: 1. Mutual exclusion: only one process at a time can use a resource. 2. Hold and wait: a process holding at least one resource is waiting to acquire additional resources held by other processes.

  5. 3. No preemption: a resource can be released only willingly by the process holding it, after that process has completed its task. 4. Circular wait: there exists a set {P0, P1, , Pn} of waiting processes such that P0is waiting for a resource that is held by P1, P1is waiting for a resource that is held by P2, , Pn 1is waiting for a resource that is held by Pn, and Pnis waiting for a resource that is held by P0.

  6. Deadlock Modeling Deadlock System Model The Deadlock System model is a way to describe and analyze systems that may be prone to deadlocks, which occur when two or more processes are unable to proceed because they are each waiting for the other to release a resource.

  7. Resource-Allocation Graph: Aset of vertices V and a set of edges E. V is partitioned into two types: P = {P1, P2, , Pn}, the set consisting of all processes in the system. R = {R1, R2, , Rm}, the set consisting of all resource types in the system. Request edge directed edge Pi Rj Assignment edge directed edge Rj Pi

  8. Process Resource Type with 4 instances Pi requests instance of Rj Pi Pi is holding an instance of Rj Pi

  9. Resource Allocation Graph With A Deadlock

  10. Graph With A Cycle But No Deadlock

  11. conclusion Basic facts: If graph contains no cycles no deadlock cycle If graph contains a if only one instance per resource type, then deadlock. if several instances per resource type, possibility of deadlock.

  12. Methods for Handling Deadlocks Ensure that the system will neverenter a deadlock state: Deadlock prevention. Deadlock avoidance. Allow the system to enter a deadlock state and then recover

  13. Deadlock Prevention 1. Mutual Exclusion cannot be broken We cannot prevent deadlocks by denying mutual exclusion because some resources are non-sharable. Sharable resources (e.g., read-only files) can be accessed concurrently.

  14. 2. Hold and Wait can be broken if A process requests a resource only if it does not hold any other resources. A process requests and is allocated all its resources before it begins execution 3. No Preemption can be broken if If a process holding some resources requests another resource that cannot be immediately allocated to it, then all resources currently being held are released. Preempted resources are added to the list of resources for which the process is waiting. Process will be restarted only when it can regain its old resources, as well as the new ones that it is requesting

  15. 4. Circular Wait can be broken if Impose a total ordering on all resource types and require that each process requests resources in an increasing order of enumeration.

  16. Deadlocks Avoidance Requires that the system has some additional a priori information available. Simplest and most useful model requires that each process declare the maximum number of resources of each type that it may need. The deadlock-avoidance algorithm dynamically examines the resource- allocation state to ensure that there can never be a circular-wait condition.

  17. System is in safe state if there exists a sequence <P1, P2, , Pn > of ALL the processes in the systems such that for each Pi, the resources that Pi can still request can be satisfied by currently available resources + resources held by all the Pj, with j < i . That is: If Pi resource needs are not immediately available, then Pi can wait until all Pj have finished. When Pj is finished, Pi can obtain needed resources, execute, return allocated resources, and terminate. When Pi terminates, Pi +1 can obtain its needed resources, and so on.

  18. Basic facts: If a system is in safe state no deadlocks. If a system is in unsafe state possibility of deadlock. Avoidance ensure that a system will never enter an unsafe state.

  19. Avoidance Algorithms: Single instance of a resource type Use a resource-allocation graph. Multiple instances of a resource type Use the banker s algorithm.

  20. Resource-Allocation Graph: Claim edge: Pi Rj indicated that process Pi may request resource Rj; represented by a dashed line. Claim edge converts to request edge when a process requests a resource. Request edge converted to an assignment edge when the resource is allocated to the process. When a resource is released by a process, assignment edge reconverts to a claim edge

  21. A cycle, as mentioned, indicates that the system is in an unsafe state. If P1 requests R2, and P2 holding R2, then a deadlock will occur.

  22. Bankers Algorithm: Multiple instances of resources. Each process must a priori claim maximum use. When a process requests a resource it may have to wait. When a process gets all its resources it must return them in a finite amount of time.

  23. Data Structures for the Bankers Algorithm: Let n = number of processes, and m = number of resources types. Available: Vector of length m. If available [j] = k, there are k instances of resource type Rj available Max: n m matrix. If Max[i,j] = k, then process Pi may request at most k instances of resource type Rj Allocation: n m matrix. If Allocation[i,j] = k then Pi is currently allocated k instances of Rj Need: n m matrix. If Need [i,j] = k, then Pi may need k more instances of Rj to complete its task Need[i,j] = Max[i,j] Allocation[i,j]

  24. Bankers Algorithm (Example): Consider the following snapshot of a system: a. What is the content of the matrix Need ? b. Is the system in a safe state? Why?

  25. Bankers Algorithm (Example): The content of the matrix Need is defined to be Max Allocation

  26. Bankers Algorithm (Example): The content of the matrix Need is defined to be Max Allocation

  27. Bankers Algorithm (Example): The content of the matrix Need is defined to be Max Allocation

  28. Bankers Algorithm (Example): b. Is the system in a safe state? Why?

  29. Bankers Algorithm (Example): b.Is the system in a safe state? Why?

  30. Bankers Algorithm (Example): b.Is the system in a safe state? Why?

  31. Bankers Algorithm (Example): b.Is the system in a safe state? Why?

  32. Bankers Algorithm (Example): b.Is the system in a safe state? Why?

  33. Bankers Algorithm (Example): b.Is the system in a safe state? Why? The system is in a safe state since the sequence < P1, P3, P0, P2, P4 > satisfies safety criteria.

  34. Recovery from Deadlock Process Termination: 1. Abort all deadlocked processes. 2. Abort one process at a time until the deadlock cycle is eliminated. 3. In which order should we choose to abort? Priority of the process. How long process has computed, and how much longer to completion. Resources the process has used. Resources process needs to complete. How many processes will need to be terminated. Is process interactive or batch?

  35. Recovery from Deadlock Resource Preemption: If preemption is required to deal with deadlocks, then three issues need to be addressed: 1. Selecting a victim Which resources and which processes are to be preempted? (minimize cost). 2. Rollback return to some safe state, restart process for that state. 3. Starvation same process may always be picked as victim, include number of rollback in cost factor.

  36. Thank you

Related


More Related Content