Operating system
This presentation is the property of its rightful owner.
Sponsored Links
1 / 71

Operating System PowerPoint PPT Presentation


  • 45 Views
  • Uploaded on
  • Presentation posted in: General

Operating System. บทที่ 7 วงจรอับ (DEADLOCK). รูปแบบของปัญหา (System Model). รูปแบบของปัญหา (System Model). รูปแบบของปัญหา (System Model).

Download Presentation

Operating System

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Operating system

Operating System

7

(DEADLOCK)


System model

(System Model)


System model1

(System Model)


System model2

(System Model)

  • 3 3 1 3 ()


Deadlock characterization

(Deadlock Characterization)


Necessary conditions

(Necessary Conditions)


Necessary conditions1

(Necessary Conditions)


Resource allocation graph

(Resource-Allocation Graph)

  • P = { P1, P2, , Pn}

  • R = { R0, R1, , Rn }

  • Pi Rj (Pi Rj) (Request Edge)

  • Rj Pi (Rj Pi) (Assignment Edge)


Resource allocation graph1

(Resource-Allocation Graph)

  • ( Rj)


Resource allocation graph2

(Resource-Allocation Graph)

  • P = { P1 , P2, P3}

  • R = { R1 , R2 , R3 , R4 }

  • E = { P1 R1, P2 R3 , R1 P2 , R2 P2 ,R2 P1 , R3 P3 }

  • R1 = 1

  • R2 = 2

  • R3 = 1

  • R4 = 3


Resource allocation graph3

(Resource-Allocation Graph)

  • P1 R2 R1

  • P2 R1 R2 R3

  • P3 R3


Resource allocation graph4

(Resource-Allocation Graph)

  • 1

  • 1

  • P3 R2 R2 P3 R2


Resource allocation graph5

(Resource-Allocation Graph)


Resource allocation graph6

(Resource-Allocation Graph)

  • 2

  • P1 R1 P2 R3 P3 R2 P1

  • P2 R3 P3 R2 P2


Resource allocation graph7

(Resource-Allocation Graph)


Resource allocation graph8

(Resource-Allocation Graph)

P1 R1 P3 R2 P1


Resource allocation graph9

(Resource-Allocation Graph)

  • P4 R2 R2 R2 P3


Methods for handing deadlocks

(Methods for Handing Deadlocks)

  • 3

  • UNIX <restart>


Deadlock prevention

(Deadlock Prevention)

  • (Mutual Exclusion)


Deadlock prevention1

(Deadlock Prevention)

  • (Hold and Wait)

  • 2

  • ()


Deadlock prevention2

(Deadlock Prevention)

  • 2

  • ()


Deadlock prevention3

(Deadlock Prevention)

  • 2


Deadlock prevention4

(Deadlock Prevention)

  • (starvation) ()


Deadlock prevention5

(Deadlock Prevention)

  • (No Preemption)

  • () ()


Deadlock prevention6

(Deadlock Prevention)

  • ()


Deadlock prevention7

(Deadlock Prevention)

  • (Circular Wait)

  • R = { R1 , R2, , Rm } R F(Ri) 2 -


Deadlock prevention8

(Deadlock Prevention)

  • F () = 1

  • F () = 5

  • F () = 12

  • Ri Rj F(Rj) > F(Ri)

  • Rj Ri F(Ri) F(Rj) R5 R1 R5 R5 R1


Deadlock prevention9

(Deadlock Prevention)

  • F () < F ()


Deadlock avoidance

(Deadlock Avoidance)

  • (Safe State)

  • (Safe State) (Safe Sequence) <P1, P2 , , Pn>


Deadlock avoidance1

(Deadlock Avoidance)

  • (unsafe state)


Deadlock avoidance2

(Deadlock Avoidance)

  • 12 3 P0 , P1 P2 P0 , P1 P2 10 , 4 9 T0 P0 , P1 P2 5 , 2 2 ( 3 )


Deadlock avoidance3

(Deadlock Avoidance)

T0 < P1, P0 , P2 >


Deadlock avoidance4

(Deadlock Avoidance)

  • T 1 P2 1

  • ()


Resource allocation graph algorithm

(Resource-Allocation Graph Algorithm)

  • (Claim Edge) Pi Rj (Pi Rj) Pi Rj ( Pi Rj)


Resource allocation graph algorithm1

(Resource-Allocation Graph Algorithm)

  • Pi Rj (Pi Rj) (Rj Pi)


Resource allocation graph algorithm2

(Resource-Allocation Graph Algorithm)


Resource allocation graph algorithm3

(Resource-Allocation Graph Algorithm)

  • P2 R2 R2 R2 P2


Resource allocation graph algorithm4

(Resource-Allocation Graph Algorithm)

  • P1 R2 P2 R1


Banker s algorithm

(Bankers Algorithm)

  • n

  • m


Banker s algorithm1

(Bankers Algorithm)

  • Available : m Available[j] = k Rj k

  • Max : n x m Max[i,j] = k Pi Rj k


Banker s algorithm2

(Bankers Algorithm)

  • Allocation : n x m Allocation[i,j] = k Pi Rj k

  • Need : n x m Need[i,j] = k Pi Rj k Need [i,j] = Max[i,j] Allocation[i,j]


Safety algorithm

(Safety Algorithm)

  • Work Finish m n

  • Work := Available;

  • For i := 1 TO n DO

  • Finish[i] := FALSE;


Safety algorithm1

(Safety Algorithm)

  • i = 1

  • WHILE i n DO BEGIN

  • IF Finish[i] = FALSE AND Need[i] Work

  • THEN BEGIN

  • Work := Work + Allocation[i];

  • Finish[i] := TRUE;

  • i := i +1; END

  • ELSE i := i+1;

  • END

  • IF some Finish[i] = FALSE THEN unsafe ELSE safe


Resource request algorithm

(Resource-Request Algorithm)

  • Requesti Pi Requesti Pi Rj k

  • Pi

  • 1. Requesti > Needi Requesti Needi 2


Resource request algorithm1

(Resource-Request Algorithm)

  • 2. Requesti > Available Pi 3 Requesti Available 3

  • 3. Pi

  • Available := Available Requesti;

  • Allocationi := Allocationi + Requesti;

  • Needi := Needi Requesti;


Resource request algorithm2

(Resource-Request Algorithm)

  • Pi ( Available , Allocationi Needi)


An illustrative example

(An Illustrative Example)

  • 5 P0 , P1 , P2 , P3 P4 3 A , B C 10 , 5 7


An illustrative example1

(An Illustrative Example)


An illustrative example2

(An Illustrative Example)

  • Need Max Allocation


An illustrative example3

(An Illustrative Example)

  • <P1, P3, P4 , P2 , P0>

  • P1 A C 1 2 Request1 = (1,0,2)

  • Request1 Need1 (1,0,2) (1,2,2)

  • Request1 Available (1,0,2) (3,3,2)


An illustrative example4

(An Illustrative Example)

  • 2


An illustrative example5

(An Illustrative Example)

  • (safety algorithm) <P1, P3, P4, P0, P2> P1

  • P4 (3,3,0) P0 (0,2,0)


Deadlock detection

(Deadlock Detection)


Single instance of each resource type

(Single Instance of Each Resource Type)

  • (Wait-for-Graph)

  • Pi Pj Pi Pj


Single instance of each resource type1

(Single Instance of Each Resource Type)

(a) (b)


Single instance of each resource type2

(Single Instance of Each Resource Type)


Several instances of a resource type

(Several Instances of a Resource Type)

  • Bankers Algorithm

  • Available : m ()

  • Allocation : n x m

  • Request : n x m


Several instances of a resource type1

(Several Instances of a Resource Type)

  • 1. Work := Available;

  • 2. FOR i:= 1 TO n DO

  • IF Allocationi 0

  • THEN Finish[i] := FALSE

  • ELSE Finish[i] := TRUE;


Several instances of a resource type2

(Several Instances of a Resource Type)

  • 3. i := 1;

  • WHILE i n DO BEGIN

  • IF Finish[i] = FALSE AND Request[i] Work

  • THEN BEGIN

  • Work := Work + Allocationi;

  • Finish[i] := TRUE;

  • i := i+1; END

  • ELSE i := i+1;

  • END;

  • 4. FOR i=1 TO n DO

  • IF Finish[i] = FALSE THEN process Pi is in a deadlocked.

  • 6. IF Finish[i] = TRUE .


Operating system

  • 5 P0 , P1 , P2 , P3 P4 A 7 , B 2 , C 6 T0


Operating system

  • (Deadlock Detection)

  • <P0 , P2 , P3 , P1 , P4> Finish[i] = TRUE


P2 c 1

P2 C 1

P0 B P1 , P2 , P3 P4


Detection algorithm usage

(Detection-Algorithm Usage)

  • 2

  • 1.

  • 2.

  • () 1 40 %


Recovery from deadlock

(Recovery from Deadlock)

  • 2

  • 1.

  • 2. 2


Process termination

(Process Termination)

  • 2 ( 2 )


Operating system

    • (Priority)

    • ( (interactive) (batch))


Resource preemption

(Resource Preemption)

  • 3

    • (Selection a victim)

    • (Rollback)

    • (Starvation)


Combined approach to deadlock handling

(Combined Approach to Deadlock Handling)

  • 1 3


Operating system

  • 4

  • (Internal Resources) PCB (Process Control Block)

  • (Central Memory)

  • (Job Resources)

  • (Swappable space) (Backing Store)


Operating system

  • 4

  • (Backing Store)


Operating system

  • (Job Control Card) (Punch cards)


  • Login