Question

In: Computer Science

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 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

ANSWER:

#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;
}

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...
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...
IN LINUX/UNIX 1. Based on the example “awkc7” introduced in the handouts, please write an awk...
IN LINUX/UNIX 1. Based on the example “awkc7” introduced in the handouts, please write an awk script to display the first six records in “loginfile.” Please test your script to make sure the script displays the following information: ics325sp200221 pts/6        75.168.197.229   Wed Apr 29 22:09 - 23:27 (01:17)     ics325sp200221 pts/10       75.168.197.229   Wed Apr 29 22:04 - 22:07 (00:02)     ics325sp200220 pts/10       24.118.187.116   Wed Apr 29 15:28 - 15:30 (00:02)     ics325sp200220 pts/10       24.118.187.116   Wed Apr 29 15:22 - 15:23 (00:00)     ics325sp200222 pts/11      ...
Write a program to simulate the Distributed Mutual Exclusion in ‘C’.
Write a program to simulate the Distributed Mutual Exclusion in ‘C’.
*****For C++ Program***** Overview For this assignment, write a program that uses functions to simulate a...
*****For C++ Program***** Overview For this assignment, write a program that uses functions to simulate a game of Craps. Craps is a game of chance where a player (the shooter) will roll 2 six-sided dice. The sum of the dice will determine whether the player (and anyone that has placed a bet) wins immediately, loses immediately, or if the game continues. If the sum of the first roll of the dice (known as the come-out roll) is equal to 7...
Using Virtualbox in Debian, write a simple program (a single .cpp file) in Linux shell C++...
Using Virtualbox in Debian, write a simple program (a single .cpp file) in Linux shell C++ Rules: -Use fork(), exec(), wait(), and exit() _______________________________________________________________________________________________________________________________________________ -A line of input represents a token group. -Each token group will result in the shell forking a new process and then executing the process. e.g. cat –n myfile.txt // a token group -Every token group must begin with a word that is called the command(see example above). The words immediately following a command are calledarguments(e.g....
Using Virtualbox in Debian, write a simple program (a single .cpp file) in Linux shell C++...
Using Virtualbox in Debian, write a simple program (a single .cpp file) in Linux shell C++ Rules: -Use fork(), exec(), wait(), and exit() _______________________________________________________________________________________________________________________________________________ -A line of input represents a token group. -Each token group will result in the shell forking a new process and then executing the process. e.g. cat –n myfile.txt // a token group -Every token group must begin with a word that is called the command(see example above). The words immediately following a command are calledarguments(e.g....
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....
Linux Directories, File Properties, and the File System in C Understanding Unix/Linux Programming Your version of...
Linux Directories, File Properties, and the File System in C Understanding Unix/Linux Programming Your version of mv command The mv command is more than just a wrapper around the rename system call. Write a version of mv that accepts two argument. The first argument must be the name of a file, and the second argument may be the name of a file or the name of a directory. If the destination is the name of a directory, then mv moves...
This program is a simple version of the linux shell using execvp by forking using C...
This program is a simple version of the linux shell using execvp by forking using C Currently this program of the shell assumes user enters no spaces before and no extra spaces between strings. Using exec, an executable binary file (eg: a.out) can be converted into a process. An example of using exec is implementing a shell program or a command interpreter. A shell program takes user commands and executes them. int execvp(const char *file, char *const argv[]); Same as...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT