//Header file declaration
#include
#include
//Global variable declaration
char newProcess[] = "New";
char runningProcess[] = "Running";
char waitingProcess[] = "Waiting";
char readyProcess[] = "Ready";
char terminatedProcess[] = "Terminating";
//
/* This method will return the state text of a given state
i.e. if you pass 1 as argument then it will return "New"
*/
const char * returnState(int state){
const char *stateText;
if(state == 0)
stateText = "New";
else if(state == 1)
stateText = "Running";
else if(state == 2)
stateText = "Waiting";
else if(state == 3)
stateText = "Ready";
else
stateText ="Terminated";
return stateText;
}
/* This method will print the status of a given process.
i.e. if process parentProcess[0] is passed as an argument
then it would use the element value to determine the status.
*/
void printStatus(int processNumber, int value){
printf(" The current status of process %d is %s.n", processNumber, returnState(value));
}
/*--- Start of main function*/
int main(void){
//Local variable declaration
int processCount; //this will hold the total number process
int index; // Index for "for loop"
printf("Hello! Please enter a whole number in between 0-10.n");
scanf("%d", &processCount);
//Local variable declaration
int parentProcess[processCount];/* This variable will store the status of each process. i.e.
if parentProcess[0] = 5 then process 1 is in terminated state, etc.
*/
/* Initially every process's status would be in new state. So, you have put 1 as value in every element
of the array. i.e. parentProcess[0] = 1 etc.
*/
for(index = 0; index < processCount; index++){
parentProcess[index] = 1;
printStatus(index, parentProcess[index]);
}
/* your code goes here*/
}
Use this code snippet as your guidance. You need to add the following options in this program
1. Give the user an option to enter different status for a process
2. Display the status of a process after a process's state has been changed by the user.
3. The program should not quit until every process's status is changed to "Terminated".