(The code should be in C) You should invoke your program by passing the number of available resources of each type on the command line.
Ex)
./a.out 3 3 2
Input: Your program will read two files:
1) containing the maximum number of each resources,
2) containing the allocation number of each resources.
Output: 1) Whether or not a system is in a safe state: “Safe” or “Not Safe”
2) If the system is in “Safe” state, print the sequence of processes satisfies the safety requirement.
Ex) <P1, P3, P4, P0, P2>
Algorithm:
Let Work and Finish be vectors of length m and n, respectively. Initialize Work = Available and Finish[i]= false for i = 0, 1, ..., n − 1.
2. Find an index i such that both
a. Finish[i]== false
b. Needi ≤ Work
If no such i exists, go to step 4.
3. Work = Work + Allocationi
Finish[i]= true
Go to step 2.
4. If Finish[i]== true for all i,then the system is in a safe state.
This algorithm may require an order of m× n^2 operations to determine whether a state is safe.
***CODE IN C***:-
#include <stdio.h>
int
main ()
{
int n, m, i, j, k;
C CODE:-
#include <stdio.h>
int
main ()
{
int n, m, i, j, k;
n = 5;
printf ("Enter maximum number of each resources");
scanf ("%d", &m);
int alloc[5][m];
printf ("Enter allocation number of each resources :\n");
for (i = 0; i < n; i++)
{
for (j = 0; j < m; j++)
{
printf ("Allocation - [%d],[%d] : ", i, j);
scanf ("%d", &alloc[i][j]);
}
}
int max[5][3] = { {7, 5, 3},
{3, 2, 2},
{2, 2, 2},
{4, 3, 3}
};
int avail[3] = { 3, 3, 2 };
int f[n], ans[n], ind = 0;
for (k = 0; k < n; k++)
{
f[k] = 0;
}
int need[n][m];
for (i = 0; i < n; i++)
{
for (j = 0; j < m; j++)
need[i][j] = max[i][j] - alloc[i][j];
}
int y = 0;
for (k = 0; k < 5; k++)
{
for (i = 0; i < n; i++)
{
if (f[i] == 0)
{
int flag = 0;
for (j = 0; j < m; j++)
{
if (need[i][j] > avail[j])
{
flag = 1;
break;
}
}
if (flag == 0)
{
ans[ind++] = i;
for (y = 0; y < m; y++)
avail[y] += alloc[i][y];
f[i] = 1;
}
}
}
}
printf("Safe and \n ") ;
printf ("Following is the SAFE Sequence\n");
for (i = 0; i < n - 1; i++)
printf (" P%d ->", ans[i]);
printf (" P%d", ans[n - 1]);
}
***INPUT AND OUTPUT***:- SCREENSHOT

*** PLEASE GIVE A THUMBS UP IN RATINGS IF YOU LIKE THE ANSWER***
(The code should be in C) You should invoke your program by passing the number of...
C++ Program Your program should: 1) Validate that the number of commandline arguments, after a.out is in the range [1,6]. If not, print an error message and stop the program with exit code 1. 2) Declare a vector of ints or array of ints to store the arguments. Use a loop to parse all the arguments (except a.out) into your vector/array. 3) Use a loop to calculate the greatest number (maximum). If the maximum is greater than 100, print "XNN"...
Hello everyone. I have a bankers algorithm written in java that gets inputs from a .txt file. The file has 7 processes and 5 resources however, when the program runs, it doesn't sum the resource columns correctly. The program runs correctly for smaller matricies (4 processes, 3 resources), not sure what the issue is and have been looking over the code for awhile so maybe another set of eyes would help...thanks BankersAlgorithm.java /** * This program implements Bankers algorithm which...
Prime Number Programing in C Note: The program is to be written using the bitwise operation. Use an integer array (not a Boolean array) and a bit length (for instance 32 bits). In this program you will write a C program to find all prime numbers less than 10,000. You should use 10,000 bits to correspond to the 10,000 integers under test. You should initially turn all bits on (off) and when a number is found that is not prime,...
In this lab you will implement tickets-for-seat-management system. The basic idea is that your program reads an event number and seat number request from a user, and determines if the seat is available (and marks it taken if it was), or is unavailable (so asking the user to choose again). As part of that exercise, you’ll be working with a file of “canned” requests to exercise your program. That is, instead of typing the requests in to your program, the...
Code the Bankers' algorithm for deadlock avoidance as described in lecture. Apply this algorithm against the following data displaying the Work, Need and Allocation matrices for each pass of the algorithm provided a safe state exists. Process Allocation Max Available A B C D A B C D A B C D P0 0 0 1 2 0 0 1 2 1 5 2 0 P1 1 0 0 0 1 7 5 0 P2 1 3 5 4 ...
I need a program in c++ the same as below code but I want it to prompt the user to enter the number of elements after that I want it to ask the user to enter the array elements #include<algorithm> #include<stdio.h> #include<string.h> #include<iostream> using namespace std; int a[50]={2,5,4,3}; bool x[100]; int N=4;//number of elements int k=10;//target sum int sum;//current target sum int cmp(const void *a,const void *b) { return *(int *)b-*(int *)a; } void backtrace(int n) { if(sum>k) return...
Consider the following snapshot of a system: Allocation P R1 R2 R3 R4 P1 0 0 1 2 P2 1 0 0 0 P3 1 3 5 4 P4 0 6 3 2 P5 0 0 1 4 P represents processes R represents resources Need P R1 R2 R3 R4 P1 0 0 1 2 P2 1 7 5 0 P3 2 3 5 6 P4 0 6 5 2 P5 0 6 5 6 P represents processes R represents...
C++ Programming Use the following function to create a program that determines whether (n ^ 2 + 1) is prime for each of the primes not exceeding 1000. bool check_prime(int input) { for(int i = 2; i <= sqrt(input); ++i) { if(input % i == 0) { return false; } } return true; }
10-13. For the systems described below, given that all of the devices are of the same type, and using the definitions presented in the discussion of the Banker's Algorithm, answer these questions: a. Calculate the number of available devices. b. Determine the remaining needs for each job in each system. c. Determine whether each system is in a safe state or an unsafe state. d. If the system is in a safe state, list the sequence of requests and releases...
Your program must be named "banker" and will read the allocation, max, available, and request vectors from a file. The name of the file will be passed to your program as a command line argument. The input file format is the following: number of processes: n number of resource types: m An n x m allocation matrix An n x m max matrix A 1 x m available vector A i : 1 x m request vector Your program will...