bankers
bankers
h>
#include <stdbool.h>
#define MAX_PROCESSES 5
#define MAX_RESOURCES 3
int count = 0;
while (count < processes) {
bool found = false;
for (int i = 0; i < processes; i++) {
if (!finish[i]) {
int canExecute = 1;
for (int j = 0; j < resources; j++) {
if (max[i][j] - allocation[i][j] > work[j]) {
canExecute = 0;
break;
}
}
if (canExecute) {
for (int k = 0; k < resources; k++) {
work[k] += allocation[i][k]; // Release resources
}
finish[i] = 1;
found = true;
count++;
}
}
}
if (!found) {
return false; // No safe sequence found
}
}
return true; // Safe sequence exists
}
int main() {
int processes, resources;
printf("Enter the number of processes: ");
scanf("%d", &processes);
printf("Enter the number of resources: ");
scanf("%d", &resources);