/** * The Banker's Algorithm * This function utilizes the Banker's Algorithm to return a safe or unsafe * value to check if a resource is available. * * @return true if safe, false if unsafe */ int bankers() { printf("\n == Running Banker's Algorithm ==\n"); // assume the state is unsafe int safe = FALSE; // set up Work array int *Work; if( !(Work = malloc( resources * sizeof( int ) ))) return -1; // copy the Available array into the temporary array for( i=0; i<resources; i++ ) { Work[i] = Available[i]; } // Find an index i such that... for( i=0; i<processes; i++ ) { // ...Finish[i] == FALSE and... if( Finish[i] == FALSE ) { // ...Need[i] <= Work for( j=0; j<resources; j++ ) { if( Need[i][j] > Work[j] ) { printf("Result is: UNSAFE."); printResources(); return safe; } } for( j=0; j < resources; j++ ) { Work[j] += Allocation[i][j]; //Finish[j] = TRUE; } // FIXME: does this go here? safe = TRUE; } } printf("Result is: %s.\n", safe ? "SAFE" : "UNSAFE"); printResources(); return safe; }
static void drminfo(char* device) { int fd; fd = open(device, O_RDONLY); fprintf(stdout, "Device %s:\n", device); printCapabilities(fd); fprintf(stdout, "\n"); printResources(fd); close(fd); }