SlideShare a Scribd company logo
1 of 16
BANKER’S ALGORITHM
Prepared by,
Prof. Samina Anjum,
Department CSE, ACET..
SYLLABUS:- Operating System
UNIT DETAILS
I
Introduction: Evolution of OS, Types of OS, Basic h/w support
necessary for modern operating systems, services provided by OS,
system programs and system calls, system design and implementation.
II
File systems: File concept, Access methods, Disk space management
and space allocation strategies, directory structures, Recovery, Log-
structured File System, disk arm scheduling strategies.
III
Scheduling: Process concept, process control block, Types of scheduler,
context switch, threads, multithreading model, goals of scheduling and
different scheduling algorithms, examples from WINDOWS 2000 &
LINUX.
SYLLABUS:- Operating System
UNIT DETAILS
IV
Memory management: Contiguous allocation, Relocation, Paging,
Segmentation, Segmentation with paging, demand paging, page faults
and instruction restart , page replacement algorithms , working sets ,
Locality, Thrashing, Garbage Collection .
V
Process cooperation and synchronization: Concurrency conditions,
Critical section problem, software and hardware solution, semaphores,
conditional critical regions and monitors, classical inter process
communication problems.
VI
Deadlocks & Protection: Deadlock definition, Prevention, Avoidance,
Detection and recovery, Goals of Protection, access matrix,
COURSE OUTCOME
CO.6 Define deadlock and implement methods for its
avoidance, detection and identify goals of protection.
Banker’s Algorithm
• Banker’s Algorithm is used to determine whether a process’s
request for allocation of resources be safely granted
immediately.
or
• The grant of request be deferred to a later stage.
• For the banker’s algorithm to operate, each process has to a
priori specify its maximum requirement of resources.
• A process is admitted for execution only if its maximum
requirement of resources is within the system capacity of
resources.
•The Banker’s algorithm is an example of resource allocation
policy that avoids deadlock.
Example:- Consider the following table of a system:
Process Allocated Max Available
R1 R2 R3 R4 R1 R2 R3 R4 R1 R2 R3 R4
P1 0 0 1 2 0 0 1 2 2 1 0 0
P2 2 0 0 0 2 7 5 0
P3 0 0 3 4 6 6 5 0
P4 2 3 5 4 4 3 5 6
P5 0 3 3 2 0 6 5 2
1. Compute NEED Matrix.
2. Is the system in safe state? Justify.
Solution:- Consider the following table of the system:
Process Allocated Max Available
R1 R2 R3 R4 R1 R2 R3 R4 R1 R2 R3 R4
P1 0 0 1 2 0 0 1 2 2 1 0 0
P2 2 0 0 0 2 7 5 0
P3 0 0 3 4 6 6 5 0
P4 2 3 5 4 4 3 5 6
P5 0 3 3 2 0 6 5 2
1. Compute NEED Matrix = ?
Need [i] = Max[i] - Allocated[i],
Therefore,
Need Matrix
NEED
MATRIX
R1 R2 R3 R4
P1 0 0 0 0
P2 0 7 5 0
P3 6 6 2 2
P4 2 0 0 0
P5 0 3 2 0
2. Is the system is Safe State?
By applying the Banker’s Algorithm:
Let Avail = Available; i.e . Avail = {2,1,0,0}
Iteration 1. Check all processes from P1 to P5.
For P1:
if (P1 Need < Avail )TRUE
then calculate
Avail= Avail + Allocated [P1]
= {2,1,0,0} + = {0,0,1,2}
Avail = {2,1,1,2}
2. Is the system is Safe State?
By applying the Banker’s Algorithm:
Iteration 1.
For P2:
if (P2 Need < Avail )FALSE
//then Check for next process.
For P3:
if (P3 Need < Avail ) FALSE
//then Check for next process.
2. Is the system is Safe State?
By applying the Banker’s Algorithm:
Iteration 1.
For P4:
if (P4 Need < Avail )TRUE
then calculate
Avail= Avail + Allocated [P4]
= {2,1,1,2} + = {2,3,5,4}
Avail = {4,4,6,6}
2. Is the system is Safe State?
By applying the Banker’s Algorithm:
Iteration 1.
For P5:
if (P5 Need < Avail )TRUE
then calculate
Avail= Avail + Allocated [P5]
= {4,4,6,6} + = {0,3,3,2}
Avail = {4,7,9,8}
2. Is the system is Safe State?
By applying the Banker’s Algorithm:
Iteration 2. Check only process P2 to P3.
For P2:
if (P2 Need < Avail )TRUE
then calculate
Avail= Avail + Allocated [P2]
= {4,7,9,8} + = {2,0,0,0}
Avail = {6,7,9,8}
2. Is the system is Safe State?
By applying the Banker’s Algorithm:
Iteration 2. Check only process P2 to P3.
For P3:
if (P3 Need < Avail )TRUE
then calculate
Avail= Avail + Allocated [P3]
= {6,7,9,8} + = {0,0,3,4}
Avail = {6,7,12,12} =System Capacity
Since, all the processes got TRUE marked, no further iterations
are required.
Therefore, Safe Sequence = P1, P4, P5, P2 , P3
Therefore, the System is in the Safe State.
THANKYOU!

More Related Content

Similar to bankers-algorithm2.pptx

BITS 1213 - OPERATING SYSTEM (PROCESS,THREAD,SYMMETRIC MULTIPROCESSOR,MICROKE...
BITS 1213 - OPERATING SYSTEM (PROCESS,THREAD,SYMMETRIC MULTIPROCESSOR,MICROKE...BITS 1213 - OPERATING SYSTEM (PROCESS,THREAD,SYMMETRIC MULTIPROCESSOR,MICROKE...
BITS 1213 - OPERATING SYSTEM (PROCESS,THREAD,SYMMETRIC MULTIPROCESSOR,MICROKE...Nur Atiqah Mohd Rosli
 
CHAPTER READING TASK OPERATING SYSTEM
CHAPTER READING TASK OPERATING SYSTEMCHAPTER READING TASK OPERATING SYSTEM
CHAPTER READING TASK OPERATING SYSTEMNur Atiqah Mohd Rosli
 
An Autonomous Self-Assessment Application to Track the Efficiency of a System...
An Autonomous Self-Assessment Application to Track the Efficiency of a System...An Autonomous Self-Assessment Application to Track the Efficiency of a System...
An Autonomous Self-Assessment Application to Track the Efficiency of a System...IOSR Journals
 
The implementation of Banker's algorithm, data structure and its parser
The implementation of Banker's algorithm, data structure and its parserThe implementation of Banker's algorithm, data structure and its parser
The implementation of Banker's algorithm, data structure and its parserMatthew Chang
 
Phase II Executive Summary 12.14.14
Phase II Executive Summary 12.14.14Phase II Executive Summary 12.14.14
Phase II Executive Summary 12.14.14haney888
 
Process Synchronization And Deadlocks
Process Synchronization And DeadlocksProcess Synchronization And Deadlocks
Process Synchronization And Deadlockstech2click
 
17 2 expert systems
17 2 expert systems17 2 expert systems
17 2 expert systemsTianlu Wang
 
Ch8 OS
Ch8 OSCh8 OS
Ch8 OSC.U
 
Performance schema in_my_sql_5.6_pluk2013
Performance schema in_my_sql_5.6_pluk2013Performance schema in_my_sql_5.6_pluk2013
Performance schema in_my_sql_5.6_pluk2013Valeriy Kravchuk
 
Macy's: Changing Engines in Mid-Flight
Macy's: Changing Engines in Mid-FlightMacy's: Changing Engines in Mid-Flight
Macy's: Changing Engines in Mid-FlightDataStax Academy
 
Ch7 OS
Ch7 OSCh7 OS
Ch7 OSC.U
 
Lecture 5- Process Synchronization (1).pptx
Lecture 5- Process Synchronization (1).pptxLecture 5- Process Synchronization (1).pptx
Lecture 5- Process Synchronization (1).pptxAmanuelmergia
 

Similar to bankers-algorithm2.pptx (20)

BITS 1213 - OPERATING SYSTEM (PROCESS,THREAD,SYMMETRIC MULTIPROCESSOR,MICROKE...
BITS 1213 - OPERATING SYSTEM (PROCESS,THREAD,SYMMETRIC MULTIPROCESSOR,MICROKE...BITS 1213 - OPERATING SYSTEM (PROCESS,THREAD,SYMMETRIC MULTIPROCESSOR,MICROKE...
BITS 1213 - OPERATING SYSTEM (PROCESS,THREAD,SYMMETRIC MULTIPROCESSOR,MICROKE...
 
Os task
Os taskOs task
Os task
 
CHAPTER READING TASK OPERATING SYSTEM
CHAPTER READING TASK OPERATING SYSTEMCHAPTER READING TASK OPERATING SYSTEM
CHAPTER READING TASK OPERATING SYSTEM
 
Distributed Operating System_2
Distributed Operating System_2Distributed Operating System_2
Distributed Operating System_2
 
An Autonomous Self-Assessment Application to Track the Efficiency of a System...
An Autonomous Self-Assessment Application to Track the Efficiency of a System...An Autonomous Self-Assessment Application to Track the Efficiency of a System...
An Autonomous Self-Assessment Application to Track the Efficiency of a System...
 
G017113537
G017113537G017113537
G017113537
 
The implementation of Banker's algorithm, data structure and its parser
The implementation of Banker's algorithm, data structure and its parserThe implementation of Banker's algorithm, data structure and its parser
The implementation of Banker's algorithm, data structure and its parser
 
Phase II Executive Summary 12.14.14
Phase II Executive Summary 12.14.14Phase II Executive Summary 12.14.14
Phase II Executive Summary 12.14.14
 
Process Synchronization And Deadlocks
Process Synchronization And DeadlocksProcess Synchronization And Deadlocks
Process Synchronization And Deadlocks
 
17 2 expert systems
17 2 expert systems17 2 expert systems
17 2 expert systems
 
Critical section operating system
Critical section  operating systemCritical section  operating system
Critical section operating system
 
Ch8 OS
Ch8 OSCh8 OS
Ch8 OS
 
Performance schema in_my_sql_5.6_pluk2013
Performance schema in_my_sql_5.6_pluk2013Performance schema in_my_sql_5.6_pluk2013
Performance schema in_my_sql_5.6_pluk2013
 
Deadlocks
DeadlocksDeadlocks
Deadlocks
 
Macy's: Changing Engines in Mid-Flight
Macy's: Changing Engines in Mid-FlightMacy's: Changing Engines in Mid-Flight
Macy's: Changing Engines in Mid-Flight
 
Ch7 OS
Ch7 OSCh7 OS
Ch7 OS
 
Introduction to SLURM
Introduction to SLURMIntroduction to SLURM
Introduction to SLURM
 
Report On HMS
Report On HMSReport On HMS
Report On HMS
 
Run time storage
Run time storageRun time storage
Run time storage
 
Lecture 5- Process Synchronization (1).pptx
Lecture 5- Process Synchronization (1).pptxLecture 5- Process Synchronization (1).pptx
Lecture 5- Process Synchronization (1).pptx
 

More from jamilmalik19

Evolution of Database Technology.pptx
Evolution of Database Technology.pptxEvolution of Database Technology.pptx
Evolution of Database Technology.pptxjamilmalik19
 
Evolution of Database Technology.pptx
Evolution of Database Technology.pptxEvolution of Database Technology.pptx
Evolution of Database Technology.pptxjamilmalik19
 
CD Store Management.pptx
CD Store Management.pptxCD Store Management.pptx
CD Store Management.pptxjamilmalik19
 
Exception Handling ,templates in C++
Exception Handling ,templates in C++Exception Handling ,templates in C++
Exception Handling ,templates in C++jamilmalik19
 
Introduction to DSA
Introduction to DSAIntroduction to DSA
Introduction to DSAjamilmalik19
 
Wildcard In database
Wildcard In databaseWildcard In database
Wildcard In databasejamilmalik19
 
What is IDE in C++?
What is IDE in C++?What is IDE in C++?
What is IDE in C++?jamilmalik19
 
introduction to C++.pptx
introduction to C++.pptxintroduction to C++.pptx
introduction to C++.pptxjamilmalik19
 
Data Types and variables in C++.pptx
Data Types and variables in C++.pptxData Types and variables in C++.pptx
Data Types and variables in C++.pptxjamilmalik19
 

More from jamilmalik19 (11)

Evolution of Database Technology.pptx
Evolution of Database Technology.pptxEvolution of Database Technology.pptx
Evolution of Database Technology.pptx
 
Deadlocks.ppt
Deadlocks.pptDeadlocks.ppt
Deadlocks.ppt
 
Evolution of Database Technology.pptx
Evolution of Database Technology.pptxEvolution of Database Technology.pptx
Evolution of Database Technology.pptx
 
CD Store Management.pptx
CD Store Management.pptxCD Store Management.pptx
CD Store Management.pptx
 
Exception Handling ,templates in C++
Exception Handling ,templates in C++Exception Handling ,templates in C++
Exception Handling ,templates in C++
 
Introduction to DSA
Introduction to DSAIntroduction to DSA
Introduction to DSA
 
Wildcard In database
Wildcard In databaseWildcard In database
Wildcard In database
 
Angular momentum
Angular momentumAngular momentum
Angular momentum
 
What is IDE in C++?
What is IDE in C++?What is IDE in C++?
What is IDE in C++?
 
introduction to C++.pptx
introduction to C++.pptxintroduction to C++.pptx
introduction to C++.pptx
 
Data Types and variables in C++.pptx
Data Types and variables in C++.pptxData Types and variables in C++.pptx
Data Types and variables in C++.pptx
 

Recently uploaded

SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxCeline George
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfDr Vijay Vishwakarma
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxAmanpreet Kaur
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxmarlenawright1
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxJisc
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Pooja Bhuva
 

Recently uploaded (20)

SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 

bankers-algorithm2.pptx

  • 1. BANKER’S ALGORITHM Prepared by, Prof. Samina Anjum, Department CSE, ACET..
  • 2. SYLLABUS:- Operating System UNIT DETAILS I Introduction: Evolution of OS, Types of OS, Basic h/w support necessary for modern operating systems, services provided by OS, system programs and system calls, system design and implementation. II File systems: File concept, Access methods, Disk space management and space allocation strategies, directory structures, Recovery, Log- structured File System, disk arm scheduling strategies. III Scheduling: Process concept, process control block, Types of scheduler, context switch, threads, multithreading model, goals of scheduling and different scheduling algorithms, examples from WINDOWS 2000 & LINUX.
  • 3. SYLLABUS:- Operating System UNIT DETAILS IV Memory management: Contiguous allocation, Relocation, Paging, Segmentation, Segmentation with paging, demand paging, page faults and instruction restart , page replacement algorithms , working sets , Locality, Thrashing, Garbage Collection . V Process cooperation and synchronization: Concurrency conditions, Critical section problem, software and hardware solution, semaphores, conditional critical regions and monitors, classical inter process communication problems. VI Deadlocks & Protection: Deadlock definition, Prevention, Avoidance, Detection and recovery, Goals of Protection, access matrix,
  • 4. COURSE OUTCOME CO.6 Define deadlock and implement methods for its avoidance, detection and identify goals of protection.
  • 5. Banker’s Algorithm • Banker’s Algorithm is used to determine whether a process’s request for allocation of resources be safely granted immediately. or • The grant of request be deferred to a later stage. • For the banker’s algorithm to operate, each process has to a priori specify its maximum requirement of resources. • A process is admitted for execution only if its maximum requirement of resources is within the system capacity of resources. •The Banker’s algorithm is an example of resource allocation policy that avoids deadlock.
  • 6. Example:- Consider the following table of a system: Process Allocated Max Available R1 R2 R3 R4 R1 R2 R3 R4 R1 R2 R3 R4 P1 0 0 1 2 0 0 1 2 2 1 0 0 P2 2 0 0 0 2 7 5 0 P3 0 0 3 4 6 6 5 0 P4 2 3 5 4 4 3 5 6 P5 0 3 3 2 0 6 5 2 1. Compute NEED Matrix. 2. Is the system in safe state? Justify.
  • 7. Solution:- Consider the following table of the system: Process Allocated Max Available R1 R2 R3 R4 R1 R2 R3 R4 R1 R2 R3 R4 P1 0 0 1 2 0 0 1 2 2 1 0 0 P2 2 0 0 0 2 7 5 0 P3 0 0 3 4 6 6 5 0 P4 2 3 5 4 4 3 5 6 P5 0 3 3 2 0 6 5 2 1. Compute NEED Matrix = ? Need [i] = Max[i] - Allocated[i], Therefore,
  • 8. Need Matrix NEED MATRIX R1 R2 R3 R4 P1 0 0 0 0 P2 0 7 5 0 P3 6 6 2 2 P4 2 0 0 0 P5 0 3 2 0
  • 9. 2. Is the system is Safe State? By applying the Banker’s Algorithm: Let Avail = Available; i.e . Avail = {2,1,0,0} Iteration 1. Check all processes from P1 to P5. For P1: if (P1 Need < Avail )TRUE then calculate Avail= Avail + Allocated [P1] = {2,1,0,0} + = {0,0,1,2} Avail = {2,1,1,2}
  • 10. 2. Is the system is Safe State? By applying the Banker’s Algorithm: Iteration 1. For P2: if (P2 Need < Avail )FALSE //then Check for next process. For P3: if (P3 Need < Avail ) FALSE //then Check for next process.
  • 11. 2. Is the system is Safe State? By applying the Banker’s Algorithm: Iteration 1. For P4: if (P4 Need < Avail )TRUE then calculate Avail= Avail + Allocated [P4] = {2,1,1,2} + = {2,3,5,4} Avail = {4,4,6,6}
  • 12. 2. Is the system is Safe State? By applying the Banker’s Algorithm: Iteration 1. For P5: if (P5 Need < Avail )TRUE then calculate Avail= Avail + Allocated [P5] = {4,4,6,6} + = {0,3,3,2} Avail = {4,7,9,8}
  • 13. 2. Is the system is Safe State? By applying the Banker’s Algorithm: Iteration 2. Check only process P2 to P3. For P2: if (P2 Need < Avail )TRUE then calculate Avail= Avail + Allocated [P2] = {4,7,9,8} + = {2,0,0,0} Avail = {6,7,9,8}
  • 14. 2. Is the system is Safe State? By applying the Banker’s Algorithm: Iteration 2. Check only process P2 to P3. For P3: if (P3 Need < Avail )TRUE then calculate Avail= Avail + Allocated [P3] = {6,7,9,8} + = {0,0,3,4} Avail = {6,7,12,12} =System Capacity
  • 15. Since, all the processes got TRUE marked, no further iterations are required. Therefore, Safe Sequence = P1, P4, P5, P2 , P3 Therefore, the System is in the Safe State.