SlideShare ist ein Scribd-Unternehmen logo
1 von 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!

Weitere ähnliche Inhalte

Ähnlich wie 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
 

Ähnlich wie 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
 

Mehr von 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
 

Mehr von 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
 

Kürzlich hochgeladen

Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
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
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Shubhangi Sonawane
 
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
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docxPoojaSen20
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 

Kürzlich hochgeladen (20)

Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
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
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
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
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
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
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).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.