Question

In: Computer Science

use linux or c program. please provide the answer in details. Write a program that will...

use linux or c program. please provide the answer in details.

Write a program that will simulate non - preemptive process scheduling algorithm:

First Come – First Serve

Your program should input the information necessary for the calculation of average turnaround time including:

  • Time required for a job execution;
  • Arrival time;

The output of the program should include: starting and terminating time for each job, turnaround time for each job, average turnaround time.

Step 1: generate the input data (totally 10 jobs) and save it in the array of structure composing the arrival time, service time, termination time, turnaround time. The service time follows the uniform distribution in the range of [5, 25], and the arrival time is generated by uniform distribution in the range of [0,10] accumulated based on the previous arrival time.

Step 2: program FCFS algorithm.

Note: be careful about the situation that one job is finished while the next job is not arrived yet, so you have the idle time between them.

Step 3: output

print out one line for each job with arrival time, start time, service, termination time, turnaround time, finally average turnaround time in the last line.

Solutions

Expert Solution

#include<iostream>
using namespace std;

// Function to find the waiting time
void Waitingtime(int processes[], int n,
                       int bt[], int wt[])
{
   // waiting time for first process is 0
   wt[0] = 0;

   // calculating waiting time for other processes
   for (int i = 1; i < n ; i++ )
       wt[i] = bt[i-1] + wt[i-1] ;
}

// Function to calculate turn around time for each process
void TAtime( int processes[], int n,
               int bt[], int wt[], int tat[])
{
   // calculating turnaround time by adding burstTime with waitingTime
  
   for (int i = 0; i < n ; i++)
       tat[i] = bt[i] + wt[i];
}

//Function to calculate average time
void AVGtime( int processes[], int n, int bt[])
{
   int wt[n], tat[n], total_wt = 0, total_tat = 0;


   Waitingtime(processes, n, bt, wt);

  
   TAtime(processes, n, bt, wt, tat);

  
   cout << "Processes "<< " Burst time "
       << " Waiting time " << " Turn around time\n";

  
   for (int i=0; i<n; i++)
   {
       total_wt = total_wt + wt[i];
       total_tat = total_tat + tat[i];
       cout << " " << i+1 << "\t\t" << bt[i] <<"\t "
           << wt[i] <<"\t\t " << tat[i] <<endl;
   }

   cout << "Average waiting time = "
       << (float)total_wt / (float)n;
   cout << "\nAverage turn around time = "
       << (float)total_tat / (float)n;
}

int main()
{
   //process id's
   int processes[] = { 1, 2, 3,4};
   int n = sizeof processes / sizeof processes[0];

   //Burst time of all processes
   int burst_time[] = {10, 5, 8,6};

   AVGtime(processes, n, burst_time);
   return 0;
}

Please kindly dont downvote please


Related Solutions

please write in c using linux or unix Write a program that will simulate non -...
please write in c using linux or unix Write a program that will simulate non - preemptive process scheduling algorithm: First Come – First Serve Your program should input the information necessary for the calculation of average turnaround time including: Time required for a job execution; Arrival time; The output of the program should include: starting and terminating time for each job, turnaround time for each job, average turnaround time. Step 1: generate the input data (totally 10 jobs) and...
Please write in C using linux or unix. Write a program that will simulate non -...
Please write in C using linux or unix. Write a program that will simulate non - preemptive process scheduling algorithm: First Come – First Serve Your program should input the information necessary for the calculation of average turnaround time including: Time required for a job execution; Arrival time; The output of the program should include: starting and terminating time for each job, turnaround time for each job, average turnaround time. Step 1: generate the input data (totally 10 jobs) and...
*Answer must be in C++ and please use a Windows machine NOT IOS! Write a program...
*Answer must be in C++ and please use a Windows machine NOT IOS! Write a program as follows: Ask the user for an integer representing a number of integers to be sorted. Create an array of integers of the size provided by user. Initialize the array to zeros. Ask the user for and populate the array with user input. Output the array elements on one line separated by a space. Write a function name “supersort” that takes an integer pointer...
Introduction Write in C++ at the Linux command line a program that is the same as...
Introduction Write in C++ at the Linux command line a program that is the same as the previous collection app project but now uses a class to store the items and also can save the items to a file that can be read back into the array by the user when the program is re-started. You can use your project 1 submission as a starting point or you can do something new as long as it meets the listed requirements....
Code in C# please. Write a program that will use the greedy algorithm. This program will...
Code in C# please. Write a program that will use the greedy algorithm. This program will ask a user to enter the cost of an item. This program will ask the user to enter the amount the user is paying. This program will return the change after subtracting the item cost by the amount paid. Using the greedy algorithm, the code should check for the type of bill. Example: Cost of item is $15.50 User pays a $20 bill $20...
IN C LANGUAGE: Write a multi-threaded Linux program that synchronizes it's threads to write to a...
IN C LANGUAGE: Write a multi-threaded Linux program that synchronizes it's threads to write to a file without the file becoming corrupted. To do this, your program will create three threads which write strings to the same file. Each thread will randomly write a selection of strings to the file at random intervals. When finished, the file will contain all the strings written correctly to the file. You may use mutexes, semaphores, or a monitor your write on your own....
PLease use c++ Write a checkbook balancing program. The program will read in, from the console,...
PLease use c++ Write a checkbook balancing program. The program will read in, from the console, the following for all checks that were not cashed as of the last time you balanced your checkbook: the number of each check (int), the amount of the check (double), and whether or not it has been cashed (1 or 0, boolean in the array). Use an array with the class as the type. The class should be a class for a check. There...
Write a “C” program(Linux) that creates a pipe and forks a child process. The parent then...
Write a “C” program(Linux) that creates a pipe and forks a child process. The parent then sends the following message on his side of the pipe “I am your daddy! and my name is <pid-of the-parent-process>\n”, the child receives this message and prints it to its stdout verbatim. The parent then blocks reading on the pipe from the child. The child writes back to its parent through its side ofthe pipe stating “Daddy, my name is <pid-of-the-child>”. The parent then...
Write an assembly language program that corresponds to the following C program ****Please give correct answer...
Write an assembly language program that corresponds to the following C program ****Please give correct answer using Pep/9 machine**** int num1; int num2; ;int main () { scanf("%d", &num1); num2 = -num1; printf("num1 = %d\n", num1); printf("num2 = %d\n", num2); return 0; }
Please if you are able to answer the question below: Write C++ program using native C++...
Please if you are able to answer the question below: Write C++ program using native C++ (you can use STL)  that produces Huffman code for a string of text entered by the user.  Must accept all ASCII characters.  Pleas explain how you got frequencies of characters, how you sorted them, how you got codes.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT