SlideShare a Scribd company logo
#include<stdio.h>
#include<conio.h>
void main()
{
int p,r,i,j,instanc,k=0,count1=0,count2=0; //count,k variables are taken
for counting purpose
int avail[10],max[10][10],allot[10][10],need[10][10],completed[10];
printf("nt Enter No. of Process:-n");
scanf("%d",&p); //Entering No. of Processes
printf("ntEnter No. of Resources:-n");
scanf("%d",&r); //No. of Resources
for(i=0;i<p;i++)
completed[i]=0; //Setting Flag for uncompleted Process
printf("ntEnter No. of Available Instancesn");
for(i=0;i<r;i++)
{
printf("tt");
scanf("%d",&instanc);
avail[i]=instanc; // Storing Available instances
}
printf("ntEnter Maximum No. of instances of resources that a Process
need:n");
for(i=0;i<p;i++)
{
printf("nt For P[%d]",i);
for(j=0;j<r;j++)
{
printf("t");
scanf("%d",&instanc);
max[i][j]=instanc;
}
}
printf("nt Enter no. of instances already allocated to process of a
resource:n");
for(i=0;i<p;i++)
{
printf("nt For P[%d]t",i);
for(j=0;j<r;j++)
{
printf("tt");
scanf("%d",&instanc);
allot[i][j]=instanc;
need[i][j]=max[i][j]-allot[i][j]; //calculating Need of each
process
}
}
printf("nt Safe Sequence is:- t");
while(count1!=p)
{
count2=count1;
for(i=0;i<p;i++)
{
for(j=0;j<r;j++)
{
if(need[i][j]<=avail[j])
{
k++;
}
}
if(k==r && completed[i]==0 )
{
printf("P[%d]t",i);
completed[i]=1;
for(j=0;j<r;j++)
{
avail[j]=avail[j]+allot[i][j];
}
count1++;
}
k=0;
}
if(count1==count2)
{
printf("tt Stop ..After this.....Deadlock n");
break;
}
}
getch();
}

More Related Content

DOCX
One dimensional operation of Array in C- language
PDF
Insertion sort
PDF
PPTX
Computer programing w
DOCX
Pratik Bakane C++
DOCX
Pratik Bakane C++
PDF
Bcsl 033 data and file structures lab s5-2
PDF
Program in ‘C’ language to implement linear search using pointers
One dimensional operation of Array in C- language
Insertion sort
Computer programing w
Pratik Bakane C++
Pratik Bakane C++
Bcsl 033 data and file structures lab s5-2
Program in ‘C’ language to implement linear search using pointers

What's hot (20)

DOCX
KEY
Ruby haskell extension
PPTX
Examples sandhiya class'
DOCX
Pratik Bakane C++
DOCX
Pratik Bakane C++
PDF
Implement a queue using two stacks.
PDF
Bcsl 033 data and file structures lab s5-3
PDF
PDF
Odd number
DOC
Palindrome number program c
DOCX
basic programs in C++
PPTX
C programming BY Mazedur
PDF
C programs Set 2
PDF
PDF
Binary search
DOC
VLSI Sequential Circuits II
DOCX
Implementation of strassens
DOCX
Circular queue
DOCX
C program to implement linked list using array abstract data type
Ruby haskell extension
Examples sandhiya class'
Pratik Bakane C++
Pratik Bakane C++
Implement a queue using two stacks.
Bcsl 033 data and file structures lab s5-3
Odd number
Palindrome number program c
basic programs in C++
C programming BY Mazedur
C programs Set 2
Binary search
VLSI Sequential Circuits II
Implementation of strassens
Circular queue
C program to implement linked list using array abstract data type
Ad

Similar to Bankers Algo Implementation (20)

TXT
Programs for Operating System
 
PDF
22-SE-77 OS_lab_labotary assignmnet#2.pdf
PDF
Bankers algorithm
PDF
Unix Programs
PDF
System Software/Operating Sytems lab report
PDF
System Software /Operating System Lab Report
DOCX
Lab manual operating system [cs 502 rgpv] (usefulsearch.org) (useful search)
PDF
Here is the code- I can't get it to work- I need a function that finds.pdf
PPT
Process Synchronization
DOCX
Os lab file c programs
DOCX
HS2021 Database Design and UseWeek 2 - 2020 Tutorial
DOCX
HS2021 Database Design and UseWeek 2 - 2020 Tutorial.docx
DOCX
Instruction1. Please read the two articles. (Kincheloe part 1 &.docx
PPTX
bankers algorithm in operating system.pptx
PPTX
Banker Algorithm in operating system.pptx
DOCX
BANKER'S ALGORITHM
PPT
PDF
PDF
c programing.Please help me with the write code libr.pdf
Programs for Operating System
 
22-SE-77 OS_lab_labotary assignmnet#2.pdf
Bankers algorithm
Unix Programs
System Software/Operating Sytems lab report
System Software /Operating System Lab Report
Lab manual operating system [cs 502 rgpv] (usefulsearch.org) (useful search)
Here is the code- I can't get it to work- I need a function that finds.pdf
Process Synchronization
Os lab file c programs
HS2021 Database Design and UseWeek 2 - 2020 Tutorial
HS2021 Database Design and UseWeek 2 - 2020 Tutorial.docx
Instruction1. Please read the two articles. (Kincheloe part 1 &.docx
bankers algorithm in operating system.pptx
Banker Algorithm in operating system.pptx
BANKER'S ALGORITHM
c programing.Please help me with the write code libr.pdf
Ad

Recently uploaded (20)

PDF
Complications of Minimal Access Surgery at WLH
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PDF
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
O7-L3 Supply Chain Operations - ICLT Program
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
Cell Structure & Organelles in detailed.
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
Trump Administration's workforce development strategy
PPTX
master seminar digital applications in india
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PPTX
GDM (1) (1).pptx small presentation for students
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PDF
Yogi Goddess Pres Conference Studio Updates
Complications of Minimal Access Surgery at WLH
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
STATICS OF THE RIGID BODIES Hibbelers.pdf
O7-L3 Supply Chain Operations - ICLT Program
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Microbial disease of the cardiovascular and lymphatic systems
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Cell Structure & Organelles in detailed.
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Trump Administration's workforce development strategy
master seminar digital applications in india
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
O5-L3 Freight Transport Ops (International) V1.pdf
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
GDM (1) (1).pptx small presentation for students
Chinmaya Tiranga quiz Grand Finale.pdf
Yogi Goddess Pres Conference Studio Updates

Bankers Algo Implementation

  • 1. #include<stdio.h> #include<conio.h> void main() { int p,r,i,j,instanc,k=0,count1=0,count2=0; //count,k variables are taken for counting purpose int avail[10],max[10][10],allot[10][10],need[10][10],completed[10]; printf("nt Enter No. of Process:-n"); scanf("%d",&p); //Entering No. of Processes printf("ntEnter No. of Resources:-n"); scanf("%d",&r); //No. of Resources for(i=0;i<p;i++) completed[i]=0; //Setting Flag for uncompleted Process printf("ntEnter No. of Available Instancesn"); for(i=0;i<r;i++) { printf("tt"); scanf("%d",&instanc); avail[i]=instanc; // Storing Available instances } printf("ntEnter Maximum No. of instances of resources that a Process need:n"); for(i=0;i<p;i++) { printf("nt For P[%d]",i); for(j=0;j<r;j++) { printf("t"); scanf("%d",&instanc); max[i][j]=instanc; } } printf("nt Enter no. of instances already allocated to process of a resource:n"); for(i=0;i<p;i++) { printf("nt For P[%d]t",i); for(j=0;j<r;j++) { printf("tt"); scanf("%d",&instanc); allot[i][j]=instanc; need[i][j]=max[i][j]-allot[i][j]; //calculating Need of each process } } printf("nt Safe Sequence is:- t"); while(count1!=p) { count2=count1; for(i=0;i<p;i++) { for(j=0;j<r;j++) { if(need[i][j]<=avail[j]) { k++; } } if(k==r && completed[i]==0 ) { printf("P[%d]t",i); completed[i]=1;