Question

In: Computer Science

Create a C program that simulates time-sharing in the operating system. Please follow the instructions provided:...

Create a C program that simulates time-sharing in the operating system.

Please follow the instructions provided:

a) Use a circular queue.

b) It is required that the process be inputted by the user. The user must input the process name and the duration in seconds, and for this simulation let the user input 5 processes.

c) As this requires process name and duration, use an array of structures.

d) To simulate time-sharing, following the algorithm presented below:

d.1) Use the sleep() function to simulate the time duration in seconds.
d.2) The CPU processes the job at the head of the queue.
d.3) The maximum time each process can execute is 10 seconds.

d.3.1) If a process has a duration of more than 10 seconds, then after running for 10 seconds it is timed out and returned to the queue (and reprocessed later).

d.3.2) Do not forget to reduce the time duration of the job by 10 seconds.

d.4) If a process has a remaining time to execute of x seconds (where x <= 10), then this process can execute until the x seconds is consumed. The process is then terminated.

d.5) As the process is executed, display the process name as well as the remaining time after it timed out.

d.6) While there are still processes left in the queue, repeat step 3b. Otherwise, the program terminates. The program shall display a message upon completion of all the jobs in the queue.

e) To test your program, try out four different sets of processes.

e.1) There should be five processes per set and each process should have its corresponding process name and duration in seconds.

e.2) In the input, if the duration is zero or negative, your program should warn the user about it and should ask the user to input again the duration.

Solutions

Expert Solution

#include <Windows.h>
#include<bits/stdc++.h>
using namespace std;

#define MAX 5

// Process Structure
struct Process {
char p_name[100]; // Process Name
int p_time; // Process Time
};

int itemCount = 0;
struct Process pro[MAX];

// Return First Process from Queue
Process getTop() {
return pro[0];
}

// Return whether Queue is empty or not
bool isEmpty() {
return itemCount==0;
}

// Insert Process
void insert(Process p) {
pro[itemCount] = p;
itemCount++;
}

// Remove Process
void removeData() {
for(int i=1;i<itemCount;i++) {
pro[i-1] = pro[i];
}
itemCount--;
}

// Main Function
int main() {
int time;
char name[100];
for(int i=0;i<MAX;i++) {
struct Process p;
scanf("%s",&p.p_name);
scanf("%d",&p.p_time);
while(p.p_time <= 0) {
printf("Process Time must be greater than or Equal to 0.");
scanf("%d",&p.p_time);
}
insert(p);
}
while(!isEmpty()) {
Process top = getTop();
if(top.p_time <= 10) {
printf("%s process is started and ends in %d sec.\n",top.p_name,top.p_time);
for(int i=0;i<top.p_time;i++) {
printf("%d sec passed...\n",i+1);
Sleep(1000);
}
removeData();
}
else {
printf("%s process is started and ends in 10 sec.\n",top.p_name);
for(int i=0;i<10;i++) {
printf("%d sec passed...\n",i+1);
Sleep(1000);
}
top.p_time = top.p_time-10;
printf("10 sec reduced in %s process with time left %d sec.\n",top.p_name,top.p_time);
removeData();
insert(top);
}
}
printf("All Processes are executed...");
return 0;
}

THANK YOU!! PLEASE VOTE


Related Solutions

Make a C program that simulates time-sharing in the operating system. Please follow the instructions provided:...
Make a C program that simulates time-sharing in the operating system. Please follow the instructions provided: a) Use a circular queue. b) It is required that the process be inputted by the user. The user must input the process name and the duration in seconds, and for this simulation let the user input 5 processes. c) As this requires process name and duration, use an array of structures. d) To simulate time-sharing, following the algorithm presented below: d.1) Use the...
Please follow the instructions and solve it by c++ Close the project and create a new...
Please follow the instructions and solve it by c++ Close the project and create a new one called 'Lab0-Part3' with the same options as in the previous step. Write a C++ program that does the following: Creates a 100-element array, either statically or dynamically Fills the array with random integers between 1 and 100 inclusive Then, creates two more 100-element arrays, one holding odd values and the other holding even values. Prints both of the new arrays to the console.
can someone code this problem please? Introduction Students will create a C++ program that simulates a...
can someone code this problem please? Introduction Students will create a C++ program that simulates a Pokemon battle mainly with the usage of a while loop, classes, structs, functions, pass by reference and arrays. Students will be expected to create the player’s pokemon and enemy pokemon using object-oriented programming (OOP). Scenario You’ve been assigned the role of creating a Pokemon fight simulator between a player’s Pikachu and the enemy CPU’s Mewtwo. You need to create a simple Pokemon battle simulation...
C++ Create a program that simulates a coin being flipped. Ask the user to guess between...
C++ Create a program that simulates a coin being flipped. Ask the user to guess between heads and tails. Let the user input 0 for heads and 1 for tails. Use a random generator to get random guesses every time. If the user guesses correctly, give them 1pt. Use a counter and initialize it to 0.   If the user does not guess correctly, subtract a point. Create a menu that allows the user to continue guessing, view the current score...
in c++ please follow instructions and fix the errors and please make a comment next to...
in c++ please follow instructions and fix the errors and please make a comment next to each code error you fix. Below are 25 code fragments, inserted into a try catch block. Each line has zero or more errors. Your task is to find and remove all errors in each fragment. Do not fix problems by simply deleting a statement; repair the problems by changing, adding, or deleting a few characters. There may be different ways to fix them You...
I need this code in C++ form using visual studios please: Create a class that simulates...
I need this code in C++ form using visual studios please: Create a class that simulates an alarm clock. In this class you should: •       Store time in hours, minutes, and seconds. Note if time is AM or PM. (Hint: You should have separate private members for the alarm and the clock. Do not forget to have a character variable representing AM or PM.) •       Initialize the clock to a specified time. •       Allow the clock to increment to the...
Please follow the instructions and solve it by C++. Thank you! What to Submit Submit the...
Please follow the instructions and solve it by C++. Thank you! What to Submit Submit the following: 1) Your .cpp file of the solution. 2) For what n value (approximately) does your computer stop producing output? Why is this? Enter your answer in the 'Comments' field when you submit the file.   So far in our study of recursion we identified a few common recursive number sequences, such as the Fibonacci numbers. Number sequences like this are not recursive algorithms themselves...
C++ Follow Instructions Please By placing a break in the IIF statement you are using it...
C++ Follow Instructions Please By placing a break in the IIF statement you are using it to force an exit from the WHILE loop. The break statement is only allowed with the SELECT/CASE statement. Also, don't use one structure to force an exit from another. Use the logic from the WHILE loop to end by removing the IF with the break #include <iostream> using namespace std; bool IsMultiple(int,int); int main() { char choice; int n1,n2; bool result; int test =...
In C++ Create a class that simulates a school calendar for a course and has a...
In C++ Create a class that simulates a school calendar for a course and has a warner that provides the school administration with the option of warning students when the last day is that a student is permitted to drop the course. (Allow administrators to warn or not, as they wish. Do not make this a required function.) You will assume in this calendar that there are 12 months in a year, 4 weeks in a month, and 7 days...
In C++  Write a program that simulates coin tossing. For each toss of the coin the program...
In C++  Write a program that simulates coin tossing. For each toss of the coin the program should print heads or tails. Let the program toss the coin 100 times and count the number times each side of the coin appears. Print the results. 0 represents tails and 1 for heads.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT