0% found this document useful (0 votes)
15 views6 pages

Amit OS Lab 07

The document is an evaluation sheet for a CSE student named Amit Mishra, detailing Experiment No. 07 which involves writing a C program to implement Banker’s Algorithm for resource allocation and deadlock avoidance in operating systems. It includes the aim, required software, theoretical background, and the complete C code for the implementation. The conclusion states that the experiment was successfully verified both theoretically and practically.

Uploaded by

Abhijit Logavi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views6 pages

Amit OS Lab 07

The document is an evaluation sheet for a CSE student named Amit Mishra, detailing Experiment No. 07 which involves writing a C program to implement Banker’s Algorithm for resource allocation and deadlock avoidance in operating systems. It includes the aim, required software, theoretical background, and the complete C code for the implementation. The conclusion states that the experiment was successfully verified both theoretically and practically.

Uploaded by

Abhijit Logavi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Student Name : Amit Mishra PRN No.

: 231111062
Course Name : CSE (IoT & CSBC) Course ID : CSL403
Year : SE Semester : IV
Roll No. : 29

EXPERIMENT EVALUATION SHEET

Experiment No. : 07
Experiment Name :

Write a C program to implement Banker’s Algorithm

MarksPerformance Correction
Sr No. Evaluation Criteria Date & Sign
(Out of 9) Date
of Instructor

1. Experiment Performance

2. Journal Performance

3. Punctuality

Total
Operating System Lab

Aim : Write a C program to implement Banker’s Algorithm.

Software required : Terminal, gcc


Theory :
Banker’s Algorithm :
Banker’s Algorithm is a resource allocation and deadlock avoidance algorithm
used in operating systems. It ensures that a system remains in a safe state by
carefully allocating resources to processes while avoiding unsafe states
that could lead to deadlocks.
1) The Banker’s Algorithm is a smart way for computer systems to manage how
programs use resources, like memory or CPU time.
2) It helps prevent situations where programs get stuck and can not finish their
tasks. This condition is known as deadlock.
3) By keeping track of what resources each program needs and what’s
available, the banker algorithm makes sure that programs only get what they
need in a safe order.

#include<stdio.h>

int main() {
int p, c, count = 0, i, j, alc[5][3], max[5][3], need[5][3], safe[5],
available[3], done[5], terminate = 0;
printf("Enter the number of process and resources");
scanf("%d %d", & p, & c);
// p is process and c is diffrent resources
printf("enter allocation of resource of all process %dx%d matrix", p,
c); for (i = 0; i < p; i++) {
for (j = 0; j < c; j++) {
scanf("%d", & alc[i][j]);}
}
Amit Mishra Roll No. : 29 Page No. : 02
Operating System Lab

printf("enter the max resource process required %dx%d matrix", p, c);


for (i = 0; i < p; i++) {
for (j = 0; j < c; j++) {
scanf("%d", & max[i][j]);
}
}
printf("enter the available resource");
for (i = 0; i < c; i++)
scanf("%d", & available[i]);

printf("\n need resources matrix are\n");


for (i = 0; i < p; i++) {
for (j = 0; j < c; j++) { need[i]
[j] = max[i][j] - alc[i][j];
printf("%d\t", need[i][j]);
}
printf("\n");
}
for (i = 0; i < p; i++)
{ done[i] = 0;
}
while (count < p)
{ for (i = 0; i < p; i+
+) { if (done[i] == 0)
{
for (j = 0; j < c; j++) {
if (need[i][j] > available[j])
break;
}
if (j == c) {
safe[count] = i;
done[i] = 1;
Amit Mishra Roll No. : 29 Page No. : 03
Operating System Lab
for (j = 0; j < c; j++) {
available[j] += alc[i][j];
}
count++;
terminate = 0;
} else {
terminate++;
}
}
}
if (terminate == (p - 1)) {
printf("safe sequence does not exist");
break;
}

}
if (terminate != (p - 1)) {
printf("\n available resource after completion\
n"); for (i = 0; i < c; i++) {
printf("%d\t", available[i]);
}
printf("\n safe sequence are\n");
for (i = 0; i < p; i++) { printf("p%d\
t", safe[i]);
}
}

return 0;
}

Amit Mishra Roll No. : 29 Page No. : 04


Operating System Lab

OUTPUT :

CONCLUSION :
Thus, we successfully verified Banker’s Algorithm and performed it
both theoretically and practically.

Amit Mishra Roll No. : 29 Page No. : 05

You might also like