Operating Systems Lab Manual / OS Dead Lock Avoidance C Program

Program Name Write a C Program for Operating System Dead Lock Avoidance (Banker‘s Algorithm)
Theory
Deadlock is a situation in which two computer programs sharing the 
same resource are effectively preventing each other from accessing 
the resource, resulting in both programs ceasing to function.

When a new process enters a system it declares the maximum number 
of instances of each resource type it needed which should not exceed the 
total number of resources in the system.


The system always determines whether the allocation of each resources will leave 
the system in safe state for any user request a set of resources . 

If the resources are not allocated to the process at the moment the 
process has to wait until some other process release the resources used by it.
Program
Input
Enter Number of Processes and Resources:4 3
Enter the Claim	matrix:
3 3 2 2
6 1 3
3 1 4
4 2 2 
Enter	the	allocation	matrix:
1 0 0
6 1 2
2 1 1
0 0 2
Resource vector:9 3 6
Output
All the resources can be allocated to Process 2

Available resources are:   6   2   3

Process 2 executed?:y 
All the resources can be allocated to Process 3

Available resources are:   8   3   4

Process 3 executed?:y 
All the resources can be allocated to Process 4

Available resources are:   8   3   6

Process 4 executed?:y 
All the resources can be allocated to Process 1

Available resources are:   9   3   6

Process 1 executed?:y 

 System is in safe mode
 The given state is safe state


Home     Back