SlideShare a Scribd company logo
1 of 25
Understand Process Management
• Deadlock Prevention




                                      1
HOME     PREVIOUS TOPIC
NEXT
PREVIOUS QUESTION PAPERS
FOR OS
CPP TUTORIALS




                           2
Recap

In the last class, you have learnt

Necessary conditions for arising Deadlocks
• Mutual exclusion

• Hold & wait

• No preemption

• Circular wait

                                             3
Objectives

On completion of this class, you would be able to know:

• Various techniques to Prevent Deadlock




                                                          4
Deadlock Prevention

• Four necessary conditions must hold for a deadlock
  to occur
• The four necessary conditions are:
   – Mutual Exclusion
   – Hold and wait
   – No Preemption
   – Circular wait
• Deadlock can be prevented if at least one of the
  above conditions does not hold
                                                     5
Deadlock Prevention
Mutual Exclusion:
• The mutual exclusion condition must hold for non-
  sharable resources
  Ex : a printer cannot be simultaneously shared by
  several processes
• A process never needs to wait for a sharable resource
• We cannot prevent deadlock by denying the mutual-
  exclusion condition
• Because some resources are non sharable             6
Deadlock Prevention

Hold & wait
•   To ensure Hold & wait never occur in the system
    We must guarantee that whenever a process requests a
    resource, it does not hold any other resources
First protocol:
• Each process must request & be allocated all its
    resources before it begins execution
Deadlock Prevention

Example :
Consider a process that
       • copies data from a tape drive to a disk file
       • Sorts the disk file and Prints the results to a printer
   •  All above resources are requested at the
     beginning of the process
   • It will hold the printer for its entire execution
   • Even though it needs the printer only at the end
Deadlock Prevention

Second Protocol:

• A process can request resources only when it has none

• i.e., If a process request any resources it must release

  all its resources that are currently allocated to it

• Refer the example in Previous slide



                                                         9
Deadlock Prevention

Second Protocol :
• The process request initially only the tape drive & Disk
  file
• It copies from tape drive to disk & then relives both
• The process request Disk file & Printer
• After copying the Disk file to the Printer
• Releases both resources and terminates

                                                          10
Deadlock Prevention

Protocols - Disadvantages:
• Resource utilization is low i.e., resources are allocated but
  unused for a long period. As discussed in example in
  slide no. 7
• Starvation is possible, because at least one of the resources
  that is requested is always allocated to some other process
• To ensure this condition does not hold

                                                          11
No Preemption
First protocol :
• If a process is holding some resources & requests
  another resource that cannot be immediately allocated
  to it
   – Then all resources currently being hold by that process are
     preempted
• The preempted resources are added to list of resources
  for which the process is waiting
• The process is restarted only when it regains its old &
  as well as new ones
                                                             12
No Preemption
Second Protocol :
• Process requests some resources
• Check whether they are available, if they are available
  allocate them to the requesting process
• If they are not, check whether they are allocated to some
  other processes that are waiting
• If so, preempt the desired resources from the waiting
  process & allocate them to requesting process
                                                      13
No Preemption


• If the resources are neither available nor held by
  waiting process, the requesting process must wait
• Process can be restarted only when it gains the
  new resources it is requesting




                                                       14
Circular wait

• To ensure that this condition never holds impose total
  ordering of all resource type
• Each process requests resources in an increasing
  order of enumeration

• Let R={R1,R2,…..Rm} be the set of resources types

• We define one-to-one F:R        N, where N is set of
  natural numbers
                                                         15
Circular wait

For Example :
• If the set of resource types R includes tape drive,
  disk drives & printers
• Then the function F might be defined as follows
                  F ( tape drive )= 1
                  F ( disk drives)= 5
                  F (printer)= 12

                                                        16
Circular wait ( Protocol )
• Each process request resources only in an increasing order of
    enumeration. i.e., a process can initially request any no. of resource
    type say Ri
• The process can request resource type Rj if and only if
     F (R j)>F (Ri)

•   Whenever a process requests a resource type R j, it can release Ri

    such that F (Ri)>=F (Rj)

• Set of Process in circular wait be {P0,P1,…..,Pn}, where Pi is waiting

    for Ri

                                                                    17
Circular wait

• Process Pi+1 is holding resource Ri while requesting

  Ri+1

• Then we must have F (Ri) < F(Ri+1), for all I

• It means F(R0) < F(R1) <….< F( Rn) < F(R0)

• By transitivity, F(R0) < F(R0), which is impossible

• Therefore there can be no circular wait               18
Summary


In this class, you have learnt

• Deadlock prevention

• To Prevent dead lock at least one of the necessary

  conditions for the dead lock does not hold




                                                   19
Frequently Asked Questions

1. Explain Deadlock Prevention ?

2. Write the protocols used hold & wait for deadlock

    prevention ?

3. Write the protocols used in No preemption for

    deadlock prevention ?



                                                   20
Quiz

1. To prevent a dead lock

a) At least are of the necessary conditions does not
    hold

b) All the necessary conditions does not hold

c) Any two of the necessary conditions does not hold

d) None


                                                   21
Quiz

2. Mutual exclusion condition must hold for _______

a) Renewable resources

b) Non renewable resources

c) CPU

d) None



                                                22
Other subject materials
•   Web designing
•   Micro processors
•   C++ tutorials
•   java

home
Quiz

3. “Each process must request & be allocated all its
    resources before it begins execution” is the protocol of

a) Mutual exclusion

b) Hold & wait

c) No preemption

d) None

                                                       24
Quiz
4. “Each process requests resources in an increasing
    order” is the protocol of

a) Mutual exclusion

b) Hold & wait

c) Circular wait

d) None


                                                  25

More Related Content

Viewers also liked

Operating System Deadlock Galvin
Operating System  Deadlock GalvinOperating System  Deadlock Galvin
Operating System Deadlock GalvinSonali Chauhan
 
Deadlock Prevention-R.D.Sivakumar
Deadlock Prevention-R.D.SivakumarDeadlock Prevention-R.D.Sivakumar
Deadlock Prevention-R.D.SivakumarSivakumar R D .
 
deadlock avoidance
deadlock avoidancedeadlock avoidance
deadlock avoidancewahab13
 
Deadlocks in operating system
Deadlocks in operating systemDeadlocks in operating system
Deadlocks in operating systemMidhun Sankar
 
Deadlocks in operating system
Deadlocks in operating systemDeadlocks in operating system
Deadlocks in operating systemSara Ali
 
Kcd226 Sistem Operasi Lecture06
Kcd226 Sistem Operasi Lecture06Kcd226 Sistem Operasi Lecture06
Kcd226 Sistem Operasi Lecture06Cahyo Darujati
 
deadlock prevention
deadlock preventiondeadlock prevention
deadlock preventionNilu Desai
 
8. mutual exclusion in Distributed Operating Systems
8. mutual exclusion in Distributed Operating Systems8. mutual exclusion in Distributed Operating Systems
8. mutual exclusion in Distributed Operating SystemsDr Sandeep Kumar Poonia
 

Viewers also liked (15)

Operating System Deadlock Galvin
Operating System  Deadlock GalvinOperating System  Deadlock Galvin
Operating System Deadlock Galvin
 
Deadlock Prevention-R.D.Sivakumar
Deadlock Prevention-R.D.SivakumarDeadlock Prevention-R.D.Sivakumar
Deadlock Prevention-R.D.Sivakumar
 
Os5
Os5Os5
Os5
 
deadlock avoidance
deadlock avoidancedeadlock avoidance
deadlock avoidance
 
Mutual exclusion
Mutual exclusionMutual exclusion
Mutual exclusion
 
Deadlock
DeadlockDeadlock
Deadlock
 
OS - Deadlock
OS - DeadlockOS - Deadlock
OS - Deadlock
 
Deadlock
DeadlockDeadlock
Deadlock
 
Deadlocks in operating system
Deadlocks in operating systemDeadlocks in operating system
Deadlocks in operating system
 
Deadlocks in operating system
Deadlocks in operating systemDeadlocks in operating system
Deadlocks in operating system
 
Deadlock ppt
Deadlock ppt Deadlock ppt
Deadlock ppt
 
Chapter 7 - Deadlocks
Chapter 7 - DeadlocksChapter 7 - Deadlocks
Chapter 7 - Deadlocks
 
Kcd226 Sistem Operasi Lecture06
Kcd226 Sistem Operasi Lecture06Kcd226 Sistem Operasi Lecture06
Kcd226 Sistem Operasi Lecture06
 
deadlock prevention
deadlock preventiondeadlock prevention
deadlock prevention
 
8. mutual exclusion in Distributed Operating Systems
8. mutual exclusion in Distributed Operating Systems8. mutual exclusion in Distributed Operating Systems
8. mutual exclusion in Distributed Operating Systems
 

Similar to 24 to 25 deadlockprevention

Similar to 24 to 25 deadlockprevention (20)

Deadlock in Operating System
Deadlock in Operating SystemDeadlock in Operating System
Deadlock in Operating System
 
6. Deadlock_1640227623705.pptx
6. Deadlock_1640227623705.pptx6. Deadlock_1640227623705.pptx
6. Deadlock_1640227623705.pptx
 
23 deadlock
23 deadlock23 deadlock
23 deadlock
 
Deadlocks Part- I.pdf
Deadlocks Part- I.pdfDeadlocks Part- I.pdf
Deadlocks Part- I.pdf
 
9 deadlock
9 deadlock9 deadlock
9 deadlock
 
Chapter5_Deadlock.pptx
Chapter5_Deadlock.pptxChapter5_Deadlock.pptx
Chapter5_Deadlock.pptx
 
OS Module-3 (2).pptx
OS Module-3 (2).pptxOS Module-3 (2).pptx
OS Module-3 (2).pptx
 
3 (1) [Autosaved].ppt
3 (1) [Autosaved].ppt3 (1) [Autosaved].ppt
3 (1) [Autosaved].ppt
 
Chapter 4
Chapter 4Chapter 4
Chapter 4
 
7308346-Deadlock.pptx
7308346-Deadlock.pptx7308346-Deadlock.pptx
7308346-Deadlock.pptx
 
deadlocks.pptx
deadlocks.pptxdeadlocks.pptx
deadlocks.pptx
 
Deadlock
DeadlockDeadlock
Deadlock
 
Deadlock
DeadlockDeadlock
Deadlock
 
Module 3 Deadlocks.pptx
Module 3 Deadlocks.pptxModule 3 Deadlocks.pptx
Module 3 Deadlocks.pptx
 
Ch 4 deadlock
Ch 4 deadlockCh 4 deadlock
Ch 4 deadlock
 
Deadlock
DeadlockDeadlock
Deadlock
 
7 Deadlocks
7 Deadlocks7 Deadlocks
7 Deadlocks
 
Deadlock
DeadlockDeadlock
Deadlock
 
Deadlock
DeadlockDeadlock
Deadlock
 
Chapter06.ppt
Chapter06.pptChapter06.ppt
Chapter06.ppt
 

More from myrajendra (20)

Fundamentals
FundamentalsFundamentals
Fundamentals
 
Data type
Data typeData type
Data type
 
Hibernate example1
Hibernate example1Hibernate example1
Hibernate example1
 
Jdbc workflow
Jdbc workflowJdbc workflow
Jdbc workflow
 
2 jdbc drivers
2 jdbc drivers2 jdbc drivers
2 jdbc drivers
 
3 jdbc api
3 jdbc api3 jdbc api
3 jdbc api
 
4 jdbc step1
4 jdbc step14 jdbc step1
4 jdbc step1
 
Dao example
Dao exampleDao example
Dao example
 
Sessionex1
Sessionex1Sessionex1
Sessionex1
 
Internal
InternalInternal
Internal
 
3. elements
3. elements3. elements
3. elements
 
2. attributes
2. attributes2. attributes
2. attributes
 
1 introduction to html
1 introduction to html1 introduction to html
1 introduction to html
 
Headings
HeadingsHeadings
Headings
 
Forms
FormsForms
Forms
 
Css
CssCss
Css
 
Views
ViewsViews
Views
 
Views
ViewsViews
Views
 
Views
ViewsViews
Views
 
Starting jdbc
Starting jdbcStarting jdbc
Starting jdbc
 

24 to 25 deadlockprevention

  • 1. Understand Process Management • Deadlock Prevention 1
  • 2. HOME PREVIOUS TOPIC NEXT PREVIOUS QUESTION PAPERS FOR OS CPP TUTORIALS 2
  • 3. Recap In the last class, you have learnt Necessary conditions for arising Deadlocks • Mutual exclusion • Hold & wait • No preemption • Circular wait 3
  • 4. Objectives On completion of this class, you would be able to know: • Various techniques to Prevent Deadlock 4
  • 5. Deadlock Prevention • Four necessary conditions must hold for a deadlock to occur • The four necessary conditions are: – Mutual Exclusion – Hold and wait – No Preemption – Circular wait • Deadlock can be prevented if at least one of the above conditions does not hold 5
  • 6. Deadlock Prevention Mutual Exclusion: • The mutual exclusion condition must hold for non- sharable resources Ex : a printer cannot be simultaneously shared by several processes • A process never needs to wait for a sharable resource • We cannot prevent deadlock by denying the mutual- exclusion condition • Because some resources are non sharable 6
  • 7. Deadlock Prevention Hold & wait • To ensure Hold & wait never occur in the system We must guarantee that whenever a process requests a resource, it does not hold any other resources First protocol: • Each process must request & be allocated all its resources before it begins execution
  • 8. Deadlock Prevention Example : Consider a process that • copies data from a tape drive to a disk file • Sorts the disk file and Prints the results to a printer • All above resources are requested at the beginning of the process • It will hold the printer for its entire execution • Even though it needs the printer only at the end
  • 9. Deadlock Prevention Second Protocol: • A process can request resources only when it has none • i.e., If a process request any resources it must release all its resources that are currently allocated to it • Refer the example in Previous slide 9
  • 10. Deadlock Prevention Second Protocol : • The process request initially only the tape drive & Disk file • It copies from tape drive to disk & then relives both • The process request Disk file & Printer • After copying the Disk file to the Printer • Releases both resources and terminates 10
  • 11. Deadlock Prevention Protocols - Disadvantages: • Resource utilization is low i.e., resources are allocated but unused for a long period. As discussed in example in slide no. 7 • Starvation is possible, because at least one of the resources that is requested is always allocated to some other process • To ensure this condition does not hold 11
  • 12. No Preemption First protocol : • If a process is holding some resources & requests another resource that cannot be immediately allocated to it – Then all resources currently being hold by that process are preempted • The preempted resources are added to list of resources for which the process is waiting • The process is restarted only when it regains its old & as well as new ones 12
  • 13. No Preemption Second Protocol : • Process requests some resources • Check whether they are available, if they are available allocate them to the requesting process • If they are not, check whether they are allocated to some other processes that are waiting • If so, preempt the desired resources from the waiting process & allocate them to requesting process 13
  • 14. No Preemption • If the resources are neither available nor held by waiting process, the requesting process must wait • Process can be restarted only when it gains the new resources it is requesting 14
  • 15. Circular wait • To ensure that this condition never holds impose total ordering of all resource type • Each process requests resources in an increasing order of enumeration • Let R={R1,R2,…..Rm} be the set of resources types • We define one-to-one F:R N, where N is set of natural numbers 15
  • 16. Circular wait For Example : • If the set of resource types R includes tape drive, disk drives & printers • Then the function F might be defined as follows F ( tape drive )= 1 F ( disk drives)= 5 F (printer)= 12 16
  • 17. Circular wait ( Protocol ) • Each process request resources only in an increasing order of enumeration. i.e., a process can initially request any no. of resource type say Ri • The process can request resource type Rj if and only if F (R j)>F (Ri) • Whenever a process requests a resource type R j, it can release Ri such that F (Ri)>=F (Rj) • Set of Process in circular wait be {P0,P1,…..,Pn}, where Pi is waiting for Ri 17
  • 18. Circular wait • Process Pi+1 is holding resource Ri while requesting Ri+1 • Then we must have F (Ri) < F(Ri+1), for all I • It means F(R0) < F(R1) <….< F( Rn) < F(R0) • By transitivity, F(R0) < F(R0), which is impossible • Therefore there can be no circular wait 18
  • 19. Summary In this class, you have learnt • Deadlock prevention • To Prevent dead lock at least one of the necessary conditions for the dead lock does not hold 19
  • 20. Frequently Asked Questions 1. Explain Deadlock Prevention ? 2. Write the protocols used hold & wait for deadlock prevention ? 3. Write the protocols used in No preemption for deadlock prevention ? 20
  • 21. Quiz 1. To prevent a dead lock a) At least are of the necessary conditions does not hold b) All the necessary conditions does not hold c) Any two of the necessary conditions does not hold d) None 21
  • 22. Quiz 2. Mutual exclusion condition must hold for _______ a) Renewable resources b) Non renewable resources c) CPU d) None 22
  • 23. Other subject materials • Web designing • Micro processors • C++ tutorials • java home
  • 24. Quiz 3. “Each process must request & be allocated all its resources before it begins execution” is the protocol of a) Mutual exclusion b) Hold & wait c) No preemption d) None 24
  • 25. Quiz 4. “Each process requests resources in an increasing order” is the protocol of a) Mutual exclusion b) Hold & wait c) Circular wait d) None 25