22BLC1012-Lab-06
22BLC1012-Lab-06
1. Simulate the Banker's algorithm to check whether the given system is in safe state
or not. Display the need matrix and safe sequence. Check if a request from process
arrives, can the request be granted immediately? Program should get the number of
process, type of resources and number of instances of each resources from the user.
The user should also provide maximum number of instances of each resource
required by the process and the allocated instances
CODE:
#include <stdio.h>
#include <stdbool.h>
if (possible) {
for (int k = 0; k < m; k++) {
work[k] += alloc[i][k];
}
safeSeq[index++] = i;
finish[i] = true;
found = true;
count++;
}
}
}
if (!found) {
printf("\nThe system is NOT in a safe state!\n");
return false;
}
}
printf("\nThe system is in a safe state.\nSafe sequence: ");
for (int i = 0; i < n; i++) {
printf("P%d ", safeSeq[i]);
}
printf("\n");
return true;
}
void processRequest(int n, int m, int max[n][m], int alloc[n][m], int avail[m], int need[n][m]) {
int process, request[m];
printf("\nEnter the process number (0 to %d) that is making a new request: ", n-1);
scanf("%d", &process);
OUTPUT: