SlideShare a Scribd company logo
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
 
G017113537
G017113537G017113537
G017113537
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 parser
Matthew 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 systems
Tianlu Wang
 
Critical section operating system
Critical section  operating systemCritical section  operating system
Critical section operating system
Muhammad Baqar Kazmi
 
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
 
Deadlocks
DeadlocksDeadlocks
Deadlocks
Shipra Swati
 
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
DataStax Academy
 
Ch7 OS
Ch7 OSCh7 OS
Ch7 OSC.U
 
Introduction to SLURM
Introduction to SLURMIntroduction to SLURM
Run time storage
Run time storageRun time storage
Run time storage
Rasineni Madhan Mohan Naidu
 
Lecture 5- Process Synchronization (1).pptx
Lecture 5- Process Synchronization (1).pptxLecture 5- Process Synchronization (1).pptx
Lecture 5- Process Synchronization (1).pptx
Amanuelmergia
 

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.pptx
jamilmalik19
 
Deadlocks.ppt
Deadlocks.pptDeadlocks.ppt
Deadlocks.ppt
jamilmalik19
 
Evolution of Database Technology.pptx
Evolution of Database Technology.pptxEvolution of Database Technology.pptx
Evolution of Database Technology.pptx
jamilmalik19
 
CD Store Management.pptx
CD Store Management.pptxCD Store Management.pptx
CD Store Management.pptx
jamilmalik19
 
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 DSA
jamilmalik19
 
Wildcard In database
Wildcard In databaseWildcard In database
Wildcard In database
jamilmalik19
 
Angular momentum
Angular momentumAngular momentum
Angular momentum
jamilmalik19
 
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++.pptx
jamilmalik19
 
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
jamilmalik19
 

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

PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
PedroFerreira53928
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
GeoBlogs
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
Vivekanand Anglo Vedic Academy
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
Col Mukteshwar Prasad
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
PedroFerreira53928
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
Excellence Foundation for South Sudan
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
Nguyen Thanh Tu Collection
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
rosedainty
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 

Recently uploaded (20)

PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 

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.