☛ Write a C program to simulate Bankers Algorithm for Deadlock Avoidance and Prevention.
Aim:
☛ Write a C program to simulate Bankers Algorithm for Deadlock Avoidance and Prevention.
Solution :
PROGRAM: ( bankers_alg.c )
#include
int main()
{
int process,resource,instance,j,i,k=0,count1=0,count2=0;
int avail[10] , max[10][10], allot[10][10],need[10][10],completed[10];
printf("Enter No. of Process: ");
scanf("%d",&process);
printf("Enter No. of Resources: ");
scanf("%d",&resource);
for(i=0;i OUTPUT:
$ gcc bankers_alg.c
$ ./a.out
Enter No. of Process: 5
Enter No. of Resources: 3
Enter No. of Available Instances: 3
3
2
Enter Maximum No. of instances of resources that a Process need:
For P[0] 7 5 3
For P[1] 3 2 2
For P[2] 9 0 2
For P[3] 2 2 2
For P[4] 4 3 3
Enter no. of instances already allocated to process of a resource:
For P[0] 0 1 0
For P[1] 2 0 0
For P[2] 3 0 2
For P[3] 2 1 1
For P[4] 0 0 2
Safe Sequence is:- P[1] P[3] P[4] P[0] P[2]
💻 Run This C Program
☛ Write a C program to simulate Bankers Algorithm for Deadlock Avoidance and Prevention.
The selected C program is loaded
automatically into the editor.
Edit the program, provide input if required
and click Run.
The compiler is embedded using OneCompiler.
Your C program is compiled and run in the embedded
Linux environment; Study Glance does not execute C code
directly on your web server.
Some Operating Systems programs (fork, pipes, FIFOs,
message queues, shared memory and semaphores) may be
restricted in an online sandbox. If a program does not
run here, compile it on a Linux system with
gcc.