Download presentation
Presentation is loading. Please wait.
Published byJewel Robbins Modified over 9 years ago
1
Deadlocks Dec 11, 2007 CPE 261403 - Operating Systems http://groups.google.com/group/cpe-os cpe-os@googlegroups.com
3
Conditions of a Deadlock (7.2.1) Mutual exclusion Hold and wait No preemption Circular wait
5
Methods for Handling Deadlocks Never allow a deadlock state Allow deadlock and then recover Ignore the problem
6
Deadlock Prevention (7.4) Prevent deadlock conditions from occurring Mutual exclusion Hold and wait No preemption Circular wait
7
Deadlock Avoidance (7.5) Figure 7.5
8
Example Max NeedsNeeds at T0 (safe) Needs at T1 (unsafe) P0422 P11055 P2923 Total number of resources = 12
9
Resource Allocation Graph
10
Banker’s Algorithm Available: Vector of length m. If available [j] = k, there are k instances of resource type R j available. Max: n x m matrix. If Max [i,j] = k, then process P i may request at most k instances of resource type R j. Allocation: n x m matrix. If Allocation[i,j] = k then P i is currently allocated k instances of R j. Need: n x m matrix. If Need[i,j] = k, then P i may need k more instances of R j to complete its task. Need [i,j] = Max[i,j] – Allocation [i,j]. Let n = number of processes, and m = number of resources types.
11
Example 5 processes P 0 through P 4 ; 3 resource types: A (10 instances), B (5instances), and C (7 instances). Snapshot at time T 0 : AllocationMaxAvailable A B C A B C A B C P 0 0 1 07 5 3 3 3 2 P 1 2 0 0 3 2 2 P 2 3 0 2 9 0 2 P 3 2 1 1 2 2 2 P 4 0 0 24 3 3
12
Safety Algorithm Work NeedFinish P0 P1 P2 P3 P4 R1R2R3
13
Safety Algorithm 743 122 600 011 431 332 Work NeedFinish P0 P1 P2 P3 P4 R1R2R3
14
Example (Cont.) The content of the matrix Need is defined to be Max – Allocation. Need A B C P 0 7 4 3 P 1 1 2 2 P 2 6 0 0 P 3 0 1 1 P 4 4 3 1 The system is in a safe state since the sequence satisfies safety criteria.
15
Process P1 makes a request for: 1 instance of A 2 instance of C Request Vector = (1,0,2)
16
Safety Algorithm after (1,0,2) request 743 122 600 011 431 332 Work NeedFinish P0 P1 P2 P3 P4 R1R2R3
17
Example: P 1 Request (1,0,2) Check that Request Available (that is, (1,0,2) (3,3,2) true. AllocationNeedAvailable A B CA B CA B C P 0 0 1 0 7 4 3 2 3 0 P 1 3 0 20 2 0 P 2 3 0 1 6 0 0 P 3 2 1 1 0 1 1 P 4 0 0 2 4 3 1 Executing safety algorithm shows that sequence satisfies safety requirement. Can request for (3,3,0) by P 4 be granted? Can request for (0,2,0) by P 0 be granted?
18
Deadlock Detection (7.6)
19
Wait-for Graphs (single instance system only) Resource-Allocation GraphCorresponding wait-for graph
20
Wait-for Graph does not work with multiple instance resources
21
Banker’s Algorithm as a deadlock detection tool for multiple instance systems
22
Deadlock Recovery (7.7)
23
Process Termination Abort all deadlock processes Abort one at a time until deadlock cycle is eliminated
24
Resource Preemption Selecting a victim – minimize cost. Rollback – return to some safe state, restart process for that state. Starvation – same process may always be picked as victim, include number of rollback in cost factor.
25
หัวข้อ present ที่เหลือ Memory Management 1. Paging - บท 8.4 2. Demand Paging - บท 9.2 Storage Management 3. File Protection - บท 10.6 4. RAID structure - บท 12.7 5. Linux File system - บท 21.7 System security 6. Program Threats - บท 18.2 ( ยกเว้น 18.2.5 Viruses) 7. Computer Viruses - บท 18.2.5 8. System & Network threats - บท 18.3 9. Cryptography - บท 18.4
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.