deadlocks cont deadlocks cont
play

Deadlocks (cont ) Deadlocks (cont.) Suppose that two pp processes - PDF document

OPERATING SYSTEMS OPERATING SYSTEMS Design and Implementation Instructor: Hadi Salimi Hadi Salimi Computer Engineering Department IRAN University of Science and Technology hsalimi@iust ac ir hsalimi@iust.ac.ir Deadlocks (cont ) Deadlocks


  1. OPERATING SYSTEMS OPERATING SYSTEMS Design and Implementation Instructor: Hadi Salimi Hadi Salimi Computer Engineering Department IRAN University of Science and Technology hsalimi@iust ac ir hsalimi@iust.ac.ir Deadlocks (cont ) Deadlocks (cont.) � Suppose that two pp processes have gained access to two resources. P1 P1 P2 P2 � If they request for the other resource and the resources resource and the resources r1 r2 could not be shared, then the deadlock occurs. the deadlock occurs. � This situation can also be occurred in software (DB) occurred in software. (DB) Operating Systems - By: Hadi Salimi - IUST-CE 2 5/29/2009

  2. Resources Resources � A resource is anything that can be used by y g y a process, like disks, printers, files and so on. � Resources can be preemptable or non- preemptable. preemptable. � Memory is an example of a preemptable resource but printer is a non-preemptable resource, but printer is a non-preemptable one. Operating Systems - By: Hadi Salimi - IUST-CE 3 5/29/2009 Resources Resources � The sequence of events required to use a q q resource is given below in an abstract form. � Request the resource. � Use the resource. � Release the resource. Operating Systems - By: Hadi Salimi - IUST-CE 4 5/29/2009

  3. Deadlock Deadlock � Deadlock can be defined formally as y follows: � A set of processes is deadlocked if each p process in the set is waiting for an event that only another process in the set can cause. � For this model, we assume that processes have only a single thread and that there y g are no interrupts possible to wake up a blocked process. Operating Systems - By: Hadi Salimi - IUST-CE 5 5/29/2009 Deadlock Conditions Deadlock Conditions � Mutual exclusion condition. Each resource is either currently assigned to exactly one process or is available currently assigned to exactly one process or is available. � Hold and wait condition. Processes currently holding resources that were granted earlier can request new resources that were granted earlier can request new resources. � No preemption condition. Resources previously granted p p p y g cannot be forcibly taken away from a process. They must be explicitly released by the process holding them. � Circular wait condition. There must be a circular chain of two or more processes, each of which is waiting for a resource held by the next member of the chain. Operating Systems - By: Hadi Salimi - IUST-CE 6 5/29/2009

  4. Deadlock Conditions Deadlock Conditions � All four of these conditions must be present for a deadlock. � If one or more of these conditions is � If one or more of these conditions is absent, no deadlock is possible. Operating Systems - By: Hadi Salimi - IUST-CE 7 5/29/2009 Deadlock Modeling Deadlock Modeling � Resource R assigned to process A � Process B is requesting/waiting for resource S q g g � Process C and D are in deadlock over resources T and U Operating Systems - By: Hadi Salimi - IUST-CE 8 5/29/2009

  5. Some Questions Some Questions � Is it possible for a batch system to go to p y g any deadlocks? � What if all schedulers act like this? � What if non of the processes do any I/O at all? Operating Systems - By: Hadi Salimi - IUST-CE 9 5/29/2009 Deadlock Modeling Deadlock Modeling Operating Systems - By: Hadi Salimi - IUST-CE 10 5/29/2009

  6. Deadlock Modeling Deadlock Modeling Operating Systems - By: Hadi Salimi - IUST-CE 11 5/29/2009 Strategies Strategies � Just Ignore the problem. g p � Detection and recovery � Prevention, by negating one of the four � Prevention by negating one of the four required conditions. � Dynamic avoidance by careful resource D i id b f l allocation. Operating Systems - By: Hadi Salimi - IUST-CE 12 5/29/2009

  7. Ostrich Algorithm Ostrich Algorithm � In some point of view, the best solution is p to pretend that there is no problem at all. � How often deadlock occurs? Does the � How often deadlock occurs? Does the frequency is greater than the frequency of system crash? system crash? � Whenever a deadlock occurs, just reboot the system. the system � Linux and MINIX act like this. Operating Systems - By: Hadi Salimi - IUST-CE 13 5/29/2009 Detection and Recovery Detection and Recovery � The system monitors the request and the release of t d th l f the resources and updates its graph. its graph. � In the case of any release or request, the graph is checked to see is there any cycle or not. If yes, kill a process in the cycle process in the cycle. � Any important point about killing a process? g p Operating Systems - By: Hadi Salimi - IUST-CE 14 5/29/2009

  8. Detection and Recovery Detection and Recovery � A somewhat cruder method is not even maintain the resource graph. � But the operating system should � But the operating system should periodically check to see if there are any processes that have been continuously processes that have been continuously blocked for more than say, 1 hour. � Such processes are killed � Such processes are killed. Operating Systems - By: Hadi Salimi - IUST-CE 15 5/29/2009 Deadlock Prevention Deadlock Prevention � Put suitable restrictions on processes so p deadlocks are impossible. � Four deadlock conditions stated by � Four deadlock conditions stated by Coffman, provide a clue for some solutions. solutions. � How to attack these 4 conditions? Operating Systems - By: Hadi Salimi - IUST-CE 16 5/29/2009

  9. Attack to Mutual Exclusion Attack to Mutual Exclusion � If no resource was assigned exclusively to g y a single process, we would never have deadlocks. � But how a resource like a printer can be used non exclusively? used non-exclusively? � Answer: � By spooling printer output several processes � By spooling printer output, several processes can generate output at the same time. � Only the printer daemon is using the printer � Only the printer daemon is using the printer. Operating Systems - By: Hadi Salimi - IUST-CE 17 5/29/2009 Attack to Hold and Wait Attack to Hold and Wait � One way to achieve this goal is to require y g q all processes to request all their resources before starting execution. g � Defects: � Many processes do not know which resources � Many processes do not know which resources they need. � Resources will not be used optimally. � Resources will not be used optimally. Operating Systems - By: Hadi Salimi - IUST-CE 18 5/29/2009

  10. Attack to no preemption Attack to no preemption � Attacking to this condition is not easy. g y � If a process has been assigned the printer and is in the middle of printing, taking and is in the middle of printing, taking away the printer because of a needed plotter is not acceptable. plotter is not acceptable. Operating Systems - By: Hadi Salimi - IUST-CE 19 5/29/2009 Attack to circular wait Attack to circular wait � A process is allowed to just have one p j resource at a time. � Is it reasonable? � Another way is to provide a global numbering for resources and all requests numbering for resources and all requests must be made in numerical order. Operating Systems - By: Hadi Salimi - IUST-CE 20 5/29/2009

  11. All Approaches All Approaches Condition Approach Mutual Exclusion Spool Everything Hold and Wait Request all resources initially No Preemption Take resources away Circular Wait Circular Wait Order resources numerically Order resources numerically Summary of all approaches to deadlock prevention. Operating Systems - By: Hadi Salimi - IUST-CE 21 5/29/2009 Deadlock Avoidance Deadlock Avoidance � Banker’s Algorithm g � Bankers’ algorithm: before granting a request, ensure that a sequence exists that will allow all processes to complete complete. Operating Systems - By: Hadi Salimi - IUST-CE 22 5/29/2009

  12. Banker’s Algorithm Banker s Algorithm E: Existing resources E: Existing resources P: Possessed resources A: Available resources Example of banker's algorithm with multiple resources Example of banker s algorithm with multiple resources Operating Systems - By: Hadi Salimi - IUST-CE 23 5/29/2009

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend