0% found this document useful (0 votes)
16 views3 pages

Banker 1

The document contains a C program that implements the Banker's algorithm for resource allocation and deadlock avoidance in operating systems. It prompts the user to input the number of processes and resources, their allocation, maximum resource requirements, and available resources, then calculates the need matrix and determines a safe sequence for process execution. The output includes the need resources matrix, available resources after completion, and the safe sequence of processes if one exists.

Uploaded by

darshansp0230
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)
16 views3 pages

Banker 1

The document contains a C program that implements the Banker's algorithm for resource allocation and deadlock avoidance in operating systems. It prompts the user to input the number of processes and resources, their allocation, maximum resource requirements, and available resources, then calculates the need matrix and determines a safe sequence for process execution. The output includes the need resources matrix, available resources after completion, and the safe sequence of processes if one exists.

Uploaded by

darshansp0230
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/ 3

#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);
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]);
}
}
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;
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;
}

Enter the number of process and resources


53
Enter allocation of resource of all process 5x3 matrix
010
200
302
211
002
Enter the max resource process required 5x3 matrix
753
322
902
422
533
Enter the available resource 3 3 2

OUTPUT
Need resources matrix are
743
122
600
211
531

Available resource after completion


10 5 7
Safe sequences are
p1 p3 p4 p0 p2

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy