SlideShare a Scribd company logo
Lecture 5

                           Deadlocks
                 5.1. Resource
                 5.2. Introduction to deadlocks
                 5.3. The ostrich algorithm
                 5.4. Deadlock detection and recovery




Sistem Operasi              http://fasilkom.narotama.ac.id/
                                                              1
Resources

• Examples of computer resources
   – printers
   – tape drives
   – tables
• Processes need access to resources in reasonable order
• Suppose a process holds resource A and requests
  resource B
   – at same time another process holds B and requests A
   – both are blocked and remain so

   Sistem Operasi       http://fasilkom.narotama.ac.id/
                                                           2
Resources (1)

• Deadlocks occur when …
  – processes are granted exclusive access to devices
  – we refer to these devices generally as resources
• Preemptable resources
  – can be taken away from a process with no ill effects
• Nonpreemptable resources
  – will cause the process to fail if taken away

  Sistem Operasi     http://fasilkom.narotama.ac.id/
                                                           3
Resources (2)

•      Sequence of events required to use a resource
     1. request the resource
     2. use the resource
     3. release the resource


•        Must wait if request is denied
     –      requesting process may be blocked
     –      may fail with error code
    Sistem Operasi       http://fasilkom.narotama.ac.id/
                                                           4
Introduction to Deadlocks

• Formal definition :
  A set of processes is deadlocked if each process in the set is waiting
  for an event that only another process in the set can cause
• Usually the event is release of a currently held resource
• None of the processes can …
   – run
   – release resources
   – be awakened


    Sistem Operasi        http://fasilkom.narotama.ac.id/
                                                                           5
Four Conditions for Deadlock

1.        Mutual exclusion condition
      •     each resource assigned to 1 process or is available
2.        Hold and wait condition
      •     process holding resources can request additional
3.        No preemption condition
      •     previously granted resources cannot forcibly taken away
4.        Circular wait condition
      •     must be a circular chain of 2 or more processes
      •     each is waiting for resource held by next member of the
            chain
     Sistem Operasi          http://fasilkom.narotama.ac.id/
                                                                      6
Deadlock Modeling (2)
• Modeled with directed graphs




     – resource R assigned to process A
     – process B is requesting/waiting for resource S
     – process C and D are in deadlock over resources T and U
Sistem Operasi        http://fasilkom.narotama.ac.id/
                                                                7
Deadlock Modeling (3)

Strategies for dealing with Deadlocks
     1.        just ignore the problem altogether
     2.        detection and recovery
     3.        dynamic avoidance
           •      careful resource allocation
     4.        prevention
           •      negating one of the four necessary conditions



Sistem Operasi               http://fasilkom.narotama.ac.id/
                                                                  8
Deadlock Modeling (4)
                         A               B              C




Sistem Operasi        http://fasilkom.narotama.ac.id/
                    How deadlock occurs                     9
Deadlock Modeling (5)




                        (o)                (p)            (q)

Sistem Operasi          http://fasilkom.narotama.ac.id/
                  How deadlock can be avoided                   10
The Ostrich Algorithm
• Pretend there is no problem
• Reasonable if
     – deadlocks occur very rarely
     – cost of prevention is high
• UNIX and Windows takes this approach
• It is a trade off between
     – convenience
     – correctness

Sistem Operasi         http://fasilkom.narotama.ac.id/
                                                         11
Detection with One Resource of Each Type (1)




• Note the resource ownership and requests
• A cycle can be found within the graph, denoting deadlock

  Sistem Operasi    http://fasilkom.narotama.ac.id/
                                                        12
Detection with One Resource of Each Type (2)




 Data structures needed by deadlock detection algorithm

  Sistem Operasi    http://fasilkom.narotama.ac.id/
                                                          13
Detection with One Resource of Each Type (3)




 An example for the deadlock detection algorithm
  Sistem Operasi   http://fasilkom.narotama.ac.id/
                                                     14
Recovery from Deadlock (1)

• Recovery through preemption
     – take a resource from some other process
     – depends on nature of the resource
• Recovery through rollback
     – checkpoint a process periodically
     – use this saved state
     – restart the process if it is found deadlocked


Sistem Operasi       http://fasilkom.narotama.ac.id/
                                                       15
Recovery from Deadlock (2)


• Recovery through killing processes
   –   crudest but simplest way to break a deadlock
   –   kill one of the processes in the deadlock cycle
   –   the other processes get its resources
   –   choose process that can be rerun from the beginning




 Sistem Operasi       http://fasilkom.narotama.ac.id/
                                                             16
Question/Discussion




Sistem Operasi        http://fasilkom.narotama.ac.id/
                                                        17

More Related Content

PDF
Kcd226 Sistem Operasi Lecture06
PDF
ikh311-05
PPTX
Unit iv: Deadlocks
PPTX
File system and Deadlocks
PDF
Real Time Operating System Concepts
DOCX
Love poem
PDF
Aprender haciendo
Kcd226 Sistem Operasi Lecture06
ikh311-05
Unit iv: Deadlocks
File system and Deadlocks
Real Time Operating System Concepts
Love poem
Aprender haciendo

Viewers also liked (20)

PDF
Patrick Lightbody Presentation Tae Slides
PPTX
Tom Ferry Presentation
PDF
Upgrading Share Point Portal Server 2003 Customizations To Share Point Server...
PPTX
Cardiovascular system or the circulatory system
PDF
Facebook, Brands and TV Preview Next Conference 2010 Berlin
PDF
Redes Sociales2
PDF
Kurikulum 2013 SMA
PDF
Sheepshead bay
DOC
Aplicaciones moviles
PDF
Colin Clark Accessible U Is With J Query And Infusion[1]
PPT
201104.wv.uva college peacebuilding le co
PPTX
S4 tarea4 gania
PPTX
Samiya Hethcock's Javita Weight Loss Testimonial
PDF
موسوعة غينس للارقام القياسيه 3
PDF
信息分类和方法
DOC
Test Analyst 3 + Yrs Manual Automation Theme
PDF
Ted Husted Presentation Testing The Testers Ae2009
PPT
Absolute Dating
PPT
Wave Energy
PPT
Variability
Patrick Lightbody Presentation Tae Slides
Tom Ferry Presentation
Upgrading Share Point Portal Server 2003 Customizations To Share Point Server...
Cardiovascular system or the circulatory system
Facebook, Brands and TV Preview Next Conference 2010 Berlin
Redes Sociales2
Kurikulum 2013 SMA
Sheepshead bay
Aplicaciones moviles
Colin Clark Accessible U Is With J Query And Infusion[1]
201104.wv.uva college peacebuilding le co
S4 tarea4 gania
Samiya Hethcock's Javita Weight Loss Testimonial
موسوعة غينس للارقام القياسيه 3
信息分类和方法
Test Analyst 3 + Yrs Manual Automation Theme
Ted Husted Presentation Testing The Testers Ae2009
Absolute Dating
Wave Energy
Variability
Ad

Similar to Kcd226 Sistem Operasi Lecture05 (20)

PPT
3 (2).ppt
PPT
3 (1) [Autosaved].ppt
DOCX
Deadlocks with example in Operating System.docx
PPTX
Deadlock_Presentation.All About Deadlocks
PPTX
deadlock and starvation resources allocation.pptx
PPTX
deadlock im operating system and their solution.pptx
PDF
Kcd226 Sistem Operasi Lecture04
PPT
06-Deadlocks.ppt
PPTX
chapter06-new.pptx
PDF
OS-Part-06.pdf
PPTX
Chapter_3_Deadlockos studentsforcomp.pptx
PPT
28 to 29 detection
PPTX
Lecture 6- Deadlocks (1) (1).pptx
PPT
Chapter 03
PPTX
Lecture 6- Deadlocks.pptx
PPTX
hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
PPTX
Deadlocks2
PDF
Deadlocks Part- I.pdf
PPTX
Algorithm 4Chapter Four- Deadlock (5).pptx
PPTX
Deadlocks
3 (2).ppt
3 (1) [Autosaved].ppt
Deadlocks with example in Operating System.docx
Deadlock_Presentation.All About Deadlocks
deadlock and starvation resources allocation.pptx
deadlock im operating system and their solution.pptx
Kcd226 Sistem Operasi Lecture04
06-Deadlocks.ppt
chapter06-new.pptx
OS-Part-06.pdf
Chapter_3_Deadlockos studentsforcomp.pptx
28 to 29 detection
Lecture 6- Deadlocks (1) (1).pptx
Chapter 03
Lecture 6- Deadlocks.pptx
hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
Deadlocks2
Deadlocks Part- I.pdf
Algorithm 4Chapter Four- Deadlock (5).pptx
Deadlocks
Ad

More from Cahyo Darujati (16)

PPTX
Presentasi jaring pengaman sandi untuk mendukung spbe 29042019 rev2
PDF
Melindungi, Mengamankan, Menanggulangi, dan Memulihkan Keamanan Informasi Pen...
PDF
Melawan penyebaran hoax di media sosial dengan teknologi
PDF
Security is a process not a magic
PPT
01.welcome.ppt.sosialisasi.skkni.surabaya
ODP
Mengatur referensi penelitian
PPTX
Tatakelola Teknologi Informasi
ODP
Pen test methodology
PPT
pengenalan ipv6
PDF
Kbk436 Sistem Operasi Lanjut Lecture02
PDF
Kbk436 Sistem Operasi Lanjut Lecture01
PDF
Kcd226 Sistem Operasi Lecture01
PDF
Kcd226 Sistem Operasi Lecture03
PDF
Kcd226 Sistem Operasi Lecture02
PDF
Kbk436 Sistem Operasi Lanjut Lecture01
PDF
Kcd226 Sistem Operasi Lecture01
Presentasi jaring pengaman sandi untuk mendukung spbe 29042019 rev2
Melindungi, Mengamankan, Menanggulangi, dan Memulihkan Keamanan Informasi Pen...
Melawan penyebaran hoax di media sosial dengan teknologi
Security is a process not a magic
01.welcome.ppt.sosialisasi.skkni.surabaya
Mengatur referensi penelitian
Tatakelola Teknologi Informasi
Pen test methodology
pengenalan ipv6
Kbk436 Sistem Operasi Lanjut Lecture02
Kbk436 Sistem Operasi Lanjut Lecture01
Kcd226 Sistem Operasi Lecture01
Kcd226 Sistem Operasi Lecture03
Kcd226 Sistem Operasi Lecture02
Kbk436 Sistem Operasi Lanjut Lecture01
Kcd226 Sistem Operasi Lecture01

Recently uploaded (20)

PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
Complications of Minimal Access Surgery at WLH
PPTX
Cell Types and Its function , kingdom of life
PDF
Basic Mud Logging Guide for educational purpose
PPTX
Lesson notes of climatology university.
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
O7-L3 Supply Chain Operations - ICLT Program
PPTX
Cell Structure & Organelles in detailed.
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
Classroom Observation Tools for Teachers
PDF
Insiders guide to clinical Medicine.pdf
PPTX
GDM (1) (1).pptx small presentation for students
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
Final Presentation General Medicine 03-08-2024.pptx
102 student loan defaulters named and shamed – Is someone you know on the list?
Module 4: Burden of Disease Tutorial Slides S2 2025
Complications of Minimal Access Surgery at WLH
Cell Types and Its function , kingdom of life
Basic Mud Logging Guide for educational purpose
Lesson notes of climatology university.
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
O7-L3 Supply Chain Operations - ICLT Program
Cell Structure & Organelles in detailed.
2.FourierTransform-ShortQuestionswithAnswers.pdf
Classroom Observation Tools for Teachers
Insiders guide to clinical Medicine.pdf
GDM (1) (1).pptx small presentation for students
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
O5-L3 Freight Transport Ops (International) V1.pdf
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
human mycosis Human fungal infections are called human mycosis..pptx

Kcd226 Sistem Operasi Lecture05

  • 1. Lecture 5 Deadlocks 5.1. Resource 5.2. Introduction to deadlocks 5.3. The ostrich algorithm 5.4. Deadlock detection and recovery Sistem Operasi http://fasilkom.narotama.ac.id/ 1
  • 2. Resources • Examples of computer resources – printers – tape drives – tables • Processes need access to resources in reasonable order • Suppose a process holds resource A and requests resource B – at same time another process holds B and requests A – both are blocked and remain so Sistem Operasi http://fasilkom.narotama.ac.id/ 2
  • 3. Resources (1) • Deadlocks occur when … – processes are granted exclusive access to devices – we refer to these devices generally as resources • Preemptable resources – can be taken away from a process with no ill effects • Nonpreemptable resources – will cause the process to fail if taken away Sistem Operasi http://fasilkom.narotama.ac.id/ 3
  • 4. Resources (2) • Sequence of events required to use a resource 1. request the resource 2. use the resource 3. release the resource • Must wait if request is denied – requesting process may be blocked – may fail with error code Sistem Operasi http://fasilkom.narotama.ac.id/ 4
  • 5. Introduction to Deadlocks • Formal definition : A set of processes is deadlocked if each process in the set is waiting for an event that only another process in the set can cause • Usually the event is release of a currently held resource • None of the processes can … – run – release resources – be awakened Sistem Operasi http://fasilkom.narotama.ac.id/ 5
  • 6. Four Conditions for Deadlock 1. Mutual exclusion condition • each resource assigned to 1 process or is available 2. Hold and wait condition • process holding resources can request additional 3. No preemption condition • previously granted resources cannot forcibly taken away 4. Circular wait condition • must be a circular chain of 2 or more processes • each is waiting for resource held by next member of the chain Sistem Operasi http://fasilkom.narotama.ac.id/ 6
  • 7. Deadlock Modeling (2) • Modeled with directed graphs – resource R assigned to process A – process B is requesting/waiting for resource S – process C and D are in deadlock over resources T and U Sistem Operasi http://fasilkom.narotama.ac.id/ 7
  • 8. Deadlock Modeling (3) Strategies for dealing with Deadlocks 1. just ignore the problem altogether 2. detection and recovery 3. dynamic avoidance • careful resource allocation 4. prevention • negating one of the four necessary conditions Sistem Operasi http://fasilkom.narotama.ac.id/ 8
  • 9. Deadlock Modeling (4) A B C Sistem Operasi http://fasilkom.narotama.ac.id/ How deadlock occurs 9
  • 10. Deadlock Modeling (5) (o) (p) (q) Sistem Operasi http://fasilkom.narotama.ac.id/ How deadlock can be avoided 10
  • 11. The Ostrich Algorithm • Pretend there is no problem • Reasonable if – deadlocks occur very rarely – cost of prevention is high • UNIX and Windows takes this approach • It is a trade off between – convenience – correctness Sistem Operasi http://fasilkom.narotama.ac.id/ 11
  • 12. Detection with One Resource of Each Type (1) • Note the resource ownership and requests • A cycle can be found within the graph, denoting deadlock Sistem Operasi http://fasilkom.narotama.ac.id/ 12
  • 13. Detection with One Resource of Each Type (2) Data structures needed by deadlock detection algorithm Sistem Operasi http://fasilkom.narotama.ac.id/ 13
  • 14. Detection with One Resource of Each Type (3) An example for the deadlock detection algorithm Sistem Operasi http://fasilkom.narotama.ac.id/ 14
  • 15. Recovery from Deadlock (1) • Recovery through preemption – take a resource from some other process – depends on nature of the resource • Recovery through rollback – checkpoint a process periodically – use this saved state – restart the process if it is found deadlocked Sistem Operasi http://fasilkom.narotama.ac.id/ 15
  • 16. Recovery from Deadlock (2) • Recovery through killing processes – crudest but simplest way to break a deadlock – kill one of the processes in the deadlock cycle – the other processes get its resources – choose process that can be rerun from the beginning Sistem Operasi http://fasilkom.narotama.ac.id/ 16
  • 17. Question/Discussion Sistem Operasi http://fasilkom.narotama.ac.id/ 17