Question

In: Other

Deadlock –Banker’s Algorithm A system has three resource types (A, B, C) and four processes {P1,...

Deadlock –Banker’s Algorithm

A system has three resource types (A, B, C) and four processes {P1, P2, P3, P4 }. The total units of system resources are: (8, 5, 4) units of A, B and C, respectively. The maximum demands for each process is P1(1,2,3), P2(3,2,1), P3(6,5,4) and P4(4,4,2). The current allocation is: P1(0,1,1), P2(2,2,0) and P3(3,0,1) and P4(1,0,1).

(a) Allocation table is given for the 3 processes with the following four columns: PROCESS, ALLOCATION, MAX and NEED. And fill this table with the current allocation state.

(b) Is this state a safe state? Explain your answer by identifying a successful future sequence of processes that makes the state safe, or by explaining which processes are part of the problem that makes the state unsafe?

PROCESS      ALLOCATION             MAX                 NEED

                            A   B   C                A   B   C            A   B   C

* P0 4 5 0 1 3 6 3 2 6 (*P0 is just an example)

   P1                    0   1   1                1   2   3           

   P2                    2   2   0                3   2   1          

   P3                    3   0   1                6   5   4           

   P4                    1   0   1                4   4   2

Solutions

Expert Solution

BANKER'S Algorithm
(a)
The banker's algorithm is designed to check the feasibility of task with a given memory and a variety of process.It is designed so that deadlock can be avoided in system

NEED=MAX-ALLOCATION
It is easy to remember the mathematical formula but the basic logic is that to known that our program will work in worst scenario and for that reason we assume this much resources we have given and in the worst case it will take max resources so the in that moment amount of resource required is taken as NEED here.

PROCESS ALLOCATION MAX NEED
A B C A B C A B C

P1 0 1 1 1 2 3 1 1 2
P2 2 2 0 3 2 1 1 0 1
P3 3 0 1 6 5 4 3 5 3
P4 1 0 1 4 4 2 3 4 1

(b)
Condition for safe state: -If all processes pass through work then it is in the safe state.

allocation[A,B,C]=[6,3,3]//it is nothing but sum of all allocation in their
// respected resource type
resource[A,B,C]=[8,5,4] //it is total sum of all resources

available[A,B,C]=resource[A,B,C]-allocation[A,B,C]//it is it's formula
=[2,2,1]
work=available=[2,2,1] // Initially we take work=available;
But as we move forward if a process is executed then we update work and that is the sum of initial work with allocation of that process.It is done so because as soon as the process is executed we can use the allocated resources of that process, for other processes to execute

Any process will take place only if work[A,B,C]>=NEED[A,B,C] for that process.

Now we will check for all process that whether they can happen or not

Now for P1
since the need of C in P1 is high then work so P1 will not execute

Now P2
Since need[A,B,C]<=work[A,B,C]
so P2 will get executed and now work will get updated
now work=work+allocation[P2]
work=[4,4,1]

Now P3
Since need[B,C]>work[B,C]
process will not take place

Now P4
Since need[A,B,C]<=work[A,B,C]
So P4 will take place
work+=allocation
work=[5,4,2]

Now P1 again
Since need[A,B,C]<=work[A,B,C]
So P1 will take place
work+=allocation
work=[5,5,3]

Now P3
Since need[A,B,C]<=work[A,B,C]
So P3 will take place
work+=allocation
work=[8,5,4]

since all the process are able to take place,this state is the safe state
and the safe sequence is


Related Solutions

Implement a C++ program to implement the Banker’s algorithm for deadlock avoidance. Number of process 5,...
Implement a C++ program to implement the Banker’s algorithm for deadlock avoidance. Number of process 5, number of resources 3 and the number of instances of each given resource is in available. You should complete the functionalities for safe state check and resource request processing. To Do 1. Complete the definition of isSafe function. The function take, the process array, 1D array of available resources, 2D array storing current allocation, and 2D array of current need. The function does not...
Consider the following snapshot of a system that has four resource types: A, B, C, and...
Consider the following snapshot of a system that has four resource types: A, B, C, and D and five processes, P0, P1, P2, P3, and P4. Allocation Max A B C D A B C D P0 3 0 1 5 5 1 1 7 P1 2 2 1 0 3 2 1 1 P2 3 1 2 1 3 3 2 1 P3 0 5 1 0 4 6 1 2 P4 4 2 1 3 6 3 2...
Consider the bankers algorithm for deadlock avoidance. Give an example of this algorithm for 7 processes...
Consider the bankers algorithm for deadlock avoidance. Give an example of this algorithm for 7 processes and 5 resource types.
1. How numerically ordered resources method prevent deadlock using example. 1. How banker’s algorithm works on...
1. How numerically ordered resources method prevent deadlock using example. 1. How banker’s algorithm works on deadlock prevention using example
Implement the Banker's algorithm for deadlock avoidance, that works on a given set of N processes...
Implement the Banker's algorithm for deadlock avoidance, that works on a given set of N processes and M resource types (N<10,M<10). Use C/C++/C# or Java for the implementation, with a simple text interface, where the user enters only the name of the input file (text only). The program reads all the necessary input data from that file. The input data and result is then displayed on the screen. You may use your program to validate the example you gave in...
1.Define each of the following terms : a. client/server system b. three-tier architecture c. deadlock 2.What...
1.Define each of the following terms : a. client/server system b. three-tier architecture c. deadlock 2.What are the six common steps needed to access databases from a typical program? 3.Contrast fat client and thin client.
Deadlocks. The Banker's algorithm is used for deadlock avoidance. Consider the state of resource availability and allocation defined by the following matrices.
Deadlocks. The Banker's algorithm is used for deadlock avoidance. Consider the state of resource availability and allocation defined by the following matrices.(1) Assuming that the total amounts for resources R1, R2, and R3 are 10, 2, and 10, should a new request to the Banker's algorithm by process P3 to acquire one additional resource from R1 and one additional resource from R3 be approved or denied? Explain why or why not(2) Assuming that the total amounts for resources R1, R2,...
Assume there are three processes A, B and C. All processes are submitted for execution at...
Assume there are three processes A, B and C. All processes are submitted for execution at the same time. The process A executes for 2 milliseconds and then does I/O for 3 milliseconds and then executes for 3 milliseconds more. The process B executes for 4 milliseconds and then does I/O for 7 milliseconds. The process C executes for 2 millisecond and then does I/O for 4 milliseconds. Assume no contention for the resources and the order of execution (priority)...
There are four conditions that must hold simultaneously in a computer system for a deadlock to...
There are four conditions that must hold simultaneously in a computer system for a deadlock to occur. Name each condition and explain what it means.
What causes deadlock in an operating system? excessive resource swapping a new processor interrupts in the...
What causes deadlock in an operating system? excessive resource swapping a new processor interrupts in the middle of servicing an existing attempt too much resource sharing a process requests a resource that is held by another waiting process
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT