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...
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....
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.
PLEASE PROVIDE COMMENTS ON STEPS Write a C++ program that modifies a string (null terminated) as...
PLEASE PROVIDE COMMENTS ON STEPS Write a C++ program that modifies a string (null terminated) as follows: Consonants are positioned at the beginning of the string and vowels are moved to the end of the string. Example : Original string : washer New string : wshrae Note: The library string functions cannot be used. You must use pointers and the switch statement to execute this program. Assume that the vowels are a, e, i, o, and u. The modification has...
CODE MUST BE IN C++ (please use for loop) write a program that loops a number...
CODE MUST BE IN C++ (please use for loop) write a program that loops a number from 1 to 10 thousand and keeps updating a count variable (count variable starts at 0 ) according to these rules: n1 = 14 n2 = 54 n3 = 123 if the number is divisible by n1, increase count by 1 if the number is divisible by n2, increase count by 2 if the number is divisible by n3, increase count by 3 if...
Please provide appropriate answer in your own words. Write some details not 2 sentences only What...
Please provide appropriate answer in your own words. Write some details not 2 sentences only What your research strategies will be for finding current, academic articles for your research paper. Explain any methods for finding good articles you have used in the past, or some ideas for how you might do research for a particular paper. Be honest about your research methods. Having more ideas about how to find good articles will be more helpful.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT