Operating System Tutorial

Operating System Tutorial Types of Operating System Evolution of Operating System Functions of Operating System Operating System Properties Operating System Services Components of Operating System Needs of the Operating System

Operating Systems

Linux Operating System Unix Operating System Ubuntu Operating System Chrome Operating Systems Fedora Operating System MAC Operating System MS Windows Operating System Solaris Operating System Cooperative Operating System CorelDRAW Operating System CentOS FreeBSD Operating Systems Batch Operating System MS-DOS Operating System Commercial Mobile Operating Systems

Differences

Difference Between Multi-programming and Multitasking Difference between C-LOOK and C-SCAN Difference between Rotational Latency and Disk Assess Time Trap vs Interrupt Difference between C-SCAN and SSTF Difference between SCAN and FCFS Difference between Seek Time and Disk Access Time Difference between SSTF and LOOK Difference between Process and Program in the Operating System Difference between Protection and Security in Operating System

How To

How to implement Monitors using Semaphores How to Install a Different Operating System on a PC

Questions

What is Kernel and Types of Kernel What is DOS Operating System What is Thread and Types of Thread What is Process Scheduler and Process Queue What is Context Switching What is CPU Scheduling What is Producer-Consumer Problem What is Semaphore in Operating System Monitors in Operating System What is Deadlock What is Paging and Segmentation What is Demand Paging What is Virtual Memory What is a Long term Scheduler What is Page Replacement in Operating System What is BSR Mode What is Convoy Effect What is Job Sequencing in Operating System Why is it critical for the Scheduler to distinguish between I/O-bound and CPU-bound programs Why is there a Need for an Operating System

Misc

Process Management Process State Scheduling Algorithm FCFS (First-come-First-Serve) Scheduling SJF (Shortest Job First) Scheduling Round-Robin CPU Scheduling Priority Based Scheduling HRRN (Highest Response Ratio Next) Scheduling Process Synchronization Lock Variable Mechanism TSL Mechanism Turn Variable Mechanism Interested Variable Mechanism Deadlock Avoidance Strategies for Handling Deadlock Deadlock Prevention Deadlock Detection and Recovery Resource Allocation Graph Banker’s Algorithm in Operating System Fixed Partitioning and Dynamic Partitioning Partitioning Algorithms Disk Scheduling Algorithms FCFS and SSTF Disk Scheduling Algorithm SCAN and C-SCAN Disk Scheduling Algorithm Look and C-Look Disk Scheduling Algorithm File in Operating System File Access Methods in Operating System File Allocation Method Directory Structure in Operating System N-Step-SCAN Disk Scheduling Feedback Queue in Operating System Contiguous Memory Allocation in Operating System Real-time Operating System Starvation in Operating System Thrashing in Operating System 5 Goals of Operating System Advantages of Operating System Advantages of UNIX Operating System Bit Vector in Operating System Booting Process in Operating System Can a Computer Run Without the Operating System Dining Philosophers Problem in Operating System Free Space Management in Operating System Inter Process Communication in Operating System Swapping in Operating System Memory Management in Operating System Multiprogramming Operating System Multitasking Operating Systems Multi-user Operating Systems Non-Contiguous Memory Allocation in Operating System Page Table in Operating System Process Scheduling in Operating System Segmentation in Operating System Simple Structure in Operating System Single-User Operating System Two Phase Locking Protocol Advantages and Disadvantages of Operating System Arithmetic operations in binary number system Assemblers in the operating system Bakery Algorithm in Operating System Benefits of Ubuntu Operating System CPU Scheduling Criteria in Operating System Critical Section in Operating System Device Management in Operating System Linux Scheduler in Operating System Long Term Scheduler in Operating System Mutex in Operating System Operating System Failure Peterson's Solution in Operating System Privileged and Non-Privileged Instructions in Operating System Swapping in Operating System Types of Operating System Zombie and Orphan Process in Operating System 62-bit operating system Advantages and Disadvantages of Batch Operating System Boot Block and Bad Block in Operating System Contiguous and Non - Contiguous Memory Allocation in Operating System Control and Distribution Systems in Operations Management Control Program in Operating System Convergent Technologies in Operating System Convoy Effect in Operating System Copy Operating Systems to SSD Core Components of Operating System Core of UNIX Operating System Correct Value to return to the Operating System Corrupted Operating System Cos is Smart Card Operating System Cosmos Operating Systems Examples Generation of Operating System Hardware Solution in Operating System Process Control Block in Operating System Function of Kernel in Operating System Operating System Layers History of Debian Operating Systems Branches and Architecture of Debian Operating Systems Features and Packages of Debian Operating Systems Installation of Operating System on a New PC Organizational Structure and Development in Debian Operating Systems User Interface in Operating System Types Of Memory in OS Operating System in Nokia Multilevel Paging in OS Memory Mapping Techniques in OS Memory Layout of a Process in Operating System Hardware Protection in Operating System Functions of File Management in Operating System Core of Linux Operating System Cache Replacement Policy in Operating System Cache Line and Cache Size in Operating System What is Memory Mapping? Difference Between Network Operating System And Distributed Operating System What is the difference between a Hard link and a Soft Link? Principles of Preemptive Scheduling Process Scheduling Algorithms What is NOS? What is the Interrupt I/O Process? What is Time Sharing OS What is process termination? What is Time-Sharing Operating System

Banker’s Algorithm in Operating System

What is Banker’s Algorithm?

Bankers algorithm is an algorithm which is used for deadlock avoidance and resource allocation. It was established by Edsger Dijkstra. The reason behind the name ‘banker’s algorithm’ is that it is mostly used in banking systems. Banker’s algorithm helps to identify whether a loan should be provided or not.

Characteristics of Banker’s Algorithm

The characteristics of Banker’s algorithm are:

  1. If a process demands the resources, then it has to wait.
  2. Banker’s algorithm consists of advanced features for maximum resource allocation.
  3. In the banker’s algorithm, various resources are maintained that fulfill the needs of at least one client.
  4. In the system, we have limited resources.
  5. In the banker’s algorithm, if the process gets all the needed resources, then it is must to return the resources in a restricted period.

Disadvantages of Banker’s Algorithm

The disadvantages of banker’s algorithm are:

  1. During processing, it does not permit a process to change its maximum need.
  2. All the processes should know in advance about the maximum resource needs.
  3. Banker’s algorithm permits the requests to be provided in constrained time, but for one year which is a fixed period.

 Data Structures used to implement the Banker’s Algorithm

There are four types of data structures used to implement Banker’s algorithm:

  1. Available
  2. Max
  3. Allocation
  4. Need

1. Available

  • Available is a one-dimensional array. The size of the array is ‘m’ which is used to determine the number of available resources of each kind.
  • Available[j] = k indicates that we have ‘k’ instances of ‘Rj’ resource type.

2. Max

  • Max is a two-dimensional array. The size of the array is ‘n*m’. The max data structure is used to determine the maximum number of resources that each process requests.
  • Max[i, j] = k indicates that ‘Pi’ can demand or request maximum ‘k’ instances of ‘Rj’ resource type.

3. Allocation

  • Allocation is a two-dimensional array, and the size of the array is ‘n*m’, which is used to define the number of resources of each kind presently assigned to each process.
  • Allocation[i, j] = k indicates that currently process ‘Pi’ is assigned ‘k’ instances of ‘Rj’ resource type.

4. Need

  • Need is a two-dimensional array. The size of the array is ‘n*m’. Need is used to define the remaining resources which are required for each process.
  • Need [i, j] = k indicates that for the execution of ‘Pi’ process, presently ‘k’ instances of resource type ‘Rj’ are required.

Banker’s algorithm comprises of two algorithms:

  1. Safety algorithm
  2. Resource request algorithm

1. Safety algorithm

The safety algorithm is used to check the system state means whether the system is in a safe state or not.

The safety algorithm contains the following steps:

Banker’s Algorithm

2. Resource Request Algorithm

Let Requesti is the request array for the process ‘Pi’. Requesti [j] = k means ‘Pi’ process needs k instances of Rj resource type. At the time   when a process Pi demands  resources, then we follow the below steps.

Banker’s Algorithm

Example of Banker’s Algorithm

Consider the following snapshot of a system:

Processes Allocation
A   B    C
      Max
A   B   C
Available
A   B   C
      P0 1     1     2  4    3    3   2    1    0
      P1 2     1     2  3    2    2  
      P2 4     0     1  9    0    2  
      P3 0     2     0  7    5    3  
      P4 1     1     2  1    1    2  
  1. calculate the content of the need matrix?
  2. Is the system in a safe state?
  3. Determine the total amount of resources of each type?

Solution:

1. Content of the need matrix can be calculated by using the below formula

Need = Max – Allocation

??
2. Now, we check for a safe state

Safe sequence:

  1.  For process P0, Need = (3, 2, 1) and

                           Available = (2, 1, 0)

             Need ? Available = False

   So, the system will move for the next process.

2. For Process P1, Need = (1, 1, 0)

                  Available = (2, 1, 0)

    Need ? Available = True

              Request of P1 is granted.

                ?                          Available = Available +Allocation

                                                              = (2, 1, 0) + (2, 1, 2)

                                                             = (4, 2, 2) (New Available)

3. For Process P2, Need = (5, 0, 1)

                   Available = (4, 2, 2)

     Need ? Available = False

So, the system will move to the next process.

4. For Process P3, Need = (7, 3, 3)

                  Available = (4, 2, 2)

          Need ? Available = False

So, the system will move to the next process.

5. For Process P4, Need = (0, 0, 0)

                   Available = (4, 2, 2)

              Need ? Available = True

                Request of P4 is granted.

                ?                          Available = Available + Allocation

                                        = (4, 2, 2) + (1, 1, 2)

                                        = (5, 3, 4) now, (New Available)

6. Now again check for Process P2, Need = (5, 0, 1)

                                               Available = (5, 3, 4)

                                          Need ? Available = True

                Request of P2 is granted.

                ?                          Available = Available + Allocation

                                                             = (5, 3, 4) + (4, 0, 1)

                                                             = (9, 3, 5) now, (New Available)

7. Now again check for Process P3, Need = (7, 3, 3)

                                              Available = (9, 3, 5)

                                          Need ? Available = True

                Request of P3 is granted.

                ?                          Available = Available +Allocation

                                                             = (9, 3, 5) + (0, 2, 0) = (9, 5, 5)

8. Now again check for Process P0, = Need (3, 2, 1)

                                                      = Available (9, 5, 5)

                         Need ? Available = True

So, the request will be granted to P0.

Safe sequence: < P1, P4, P2, P3, P0>

The system allocates all the needed resources to each process. So, we can say that system is in a safe state.

3. The total amount of resources = sum of columns of allocation + Available

                                                             = [8 5 7] + [2 1 0] = [10 6 7]