Question

Operating System Theory and Design

Write a program to simulate the operation of two of CPU scheduling methods. The program does the following: 1. Get the number of processes from the user. 2. Get the burst time of each process from the user 3. Assume that all processes arrive at O to the ready queue. 4. The program lets the user select one of the two methods to implement the o e oo implement the CPU scheduling. time. You can use any programming language you would like to use. 5. The program calculates the average waiting time and the average turnaround 6. The program shows scheduling time of the CPU by using Gant Chart or table.




0 0
Add a comment Improve this question Transcribed image text
Answer #1


#include<iostream>
using namespace std;
void findsjf (int processes[], int n, int bt[])
{
   int i, j;
for (i = 0; i < n-1; i++)     
{
     
   for (j = 0; j < n-i-1; j++)
   {
         
       if (bt[j] > bt[j+1])
       {
           int temp = bt[j];
   bt[j] = bt[j+1];
   bt[j+1] = temp;
       }
   }
}
int wait[n], trn_arnd_time[n], total_wt = 0, total_trn_arnd_time = 0;
wait[0] = 0;

  
   for (int i = 1; i < n ; i++ )
       wait[i] = bt[i-1] + wait[i-1] ;
      
       for (int i = 0; i < n ; i++)
       trn_arnd_time[i] = bt[i] + wait[i];

  
   cout << "Processes "<< " Burst time "<< " Waiting time " << " Turn around time\n";
       for (int i=0; i<n; i++)
   {
       total_wt = total_wt + wait[i];
       total_trn_arnd_time = total_trn_arnd_time + trn_arnd_time[i];
       cout << " " << i+1 << "\t\t" << bt[i] <<"\t "<< wait[i] <<"\t\t " << trn_arnd_time[i] <<endl;
   }

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

void findfcfs( int processes[], int n, int bt[])
{
   int wait[n], trn_arnd_time[n], total_wait = 0, total_trn_arnd_time = 0;

  
   wait[0] = 0;

  
   for (int i = 1; i < n ; i++ )
       wait[i] = bt[i-1] + wait[i-1] ;

  
   for (int i = 0; i < n ; i++)
       trn_arnd_time[i] = bt[i] + wait[i];

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

  
   for (int i=0; i<n; i++)
   {
       total_wait = total_wait + wait[i];
       total_trn_arnd_time = total_trn_arnd_time + trn_arnd_time[i];
       cout << " " << i+1 << "\t\t" << bt[i] <<"\t "
           << wait[i] <<"\t\t " << trn_arnd_time[i] <<endl;
   }

   cout << "Average waiting time is = "<< (float)total_wait / (float)n;
   cout << "\nAverage turn around time is = "<< (float)total_trn_arnd_time / (float)n;
}


int main()
{
int n, choice ;
cout<<"enter the number of processes"<<endl;
   cin>> n;
   int processes[n] ;
     
   int burst_time[n];
   cout<<"enter the burst times"<<endl;
   for(int i = 0;i<n;i++)
   {
       cin>>burst_time[i];
   }
   for(int j = 0;j<n;j++)
   {
       processes[j]= j+1;
   }
   cout<<"Press 1 to choose FCFS and press 2 to choose SJF"<<endl;
   cin>>choice;
   switch(choice)
   {
       case 1 :
       findfcfs(processes, n, burst_time);
       break;
       case 2:
   findsjf(processes, n, burst_time);
   break;
   default:
   cout<<"choice is not correct";
   }

  
  
   return 0;
}

Add a comment
Know the answer?
Add Answer to:
Operating System Theory and Design Write a program to simulate the operation of two of CPU...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Implement the following 3 CPU scheduling algorithms Simulate and evaluate each with the set of eight...

    Implement the following 3 CPU scheduling algorithms Simulate and evaluate each with the set of eight processes below. Use any programming language. The program listing should be submitted with the report. FCFS (First Come First Serve) non-preemptive (partial results provided) SJF non-preemptive MLFQ Multilevel Feedback Queue (absolute priority in higher queues)             Queue 1 uses RR scheduling with Tq = 5             Queue 2 uses RR scheduling with Tq = 10             Queue 3 uses FCFS All processes enter first...

  • Write a Java program that will simulate SRTnext scheduling algorithms. For the algorithm, the pro...

    Write a Java program that will simulate SRTnext scheduling algorithms. For the algorithm, the program should compute waiting time and turnaround time of every job as well as the average waiting time and average turn around time Process Arrival time CPU Burst (in milliseconds) 6 P1 P2 P3 7 10 Ps Write a Java program that will simulate SRTnext scheduling algorithms. For the algorithm, the program should compute waiting time and turnaround time of every job as well as the...

  • Description In this homework, you are asked to implement a multithreaded program that will allow ...

    Description In this homework, you are asked to implement a multithreaded program that will allow us to measure the performance (i.e, CPU utilization, Throughput, Turnaround time, and Waiting time in Ready Queue) of the four basic CPU scheduling algorithms (namely, FIFO, SJE PR, and RR). Your program will be emulating/simulating the processes whose priority, sequence of CPU burst time(ms) and I'O burst time(ms) will be given in an input file. Assume that all scheduling algorithms except RR will be non-preemptive,...

  • This is a C program question you will implement a program to show the performance of...

    This is a C program question you will implement a program to show the performance of FCFS scheduling algorithm with I/O burst. Your program should get a file (e.g., “jobs.txt”) as the command-line input, and read the contents of the file. This file contains a set of processes. For example, consider the file with the following content: 1:(45,15);(16,20);(80,10);(40,-1) 2:(15,10);(60,15);(90,10);(85,20);(20,-1) 3:(30,15);(40,20);(5,15);(10,15);(15,-1) In this example we have 3 processes, each process is represented in a separate line. The general format of a...

  • Implement a First Come First Serve (FCFS) non-preemptive OS scheduling simulation with multiple processes, in python...

    Implement a First Come First Serve (FCFS) non-preemptive OS scheduling simulation with multiple processes, in python or c++. The simulation takes the 3 processes(listed below) and they all arrive at time 0. A single process consists of {CPU BURST, I/O BURST, CPU BURST, I/O BURST, etc…} The simulation accounts for all 3 processes, and does not run one process at a time. Process1 {4,24,5,73,3,31,5,27,4,33,6,43,4,64,5,19,2} Process2 {18,31,19,35,11,42,18,43,19,47,18,43,17,51,19,32,10} Process3 {6,18,4,21,7,19,4,16,5,29,7,21,8,22,6,24,5} For example at time 0, Process1 arrives and enters running state, Process2...

  • Consider the following set of processes, with the length of the CPU-burst time given in milliseconds:

    Consider the following set of processes, with the length of the CPU-burst time given in milliseconds:Processburst TimePriorityP1103P211P323P414P552For each of the scheduling algorithms, FCFS, Shortest-Job-First (SJF, non-preemptive), Priority (smaller priority number implies higher scheduling priority), and RR (quantum = 1) do the following.Draw a Gantt chart to show how these processes would be scheduled.Give the turnaround time (total time from the first arrival into ready state until CPU-burst is completed) of each process.Give the waiting time (total time spent in the Ready state) of each process.Give...

  • This assignment requires you to create simulations for different scheduling algorithms commonly employed by operating systems...

    This assignment requires you to create simulations for different scheduling algorithms commonly employed by operating systems to achieve multiprogramming. All problems in this assignment assume the following: The simulations you will be creating are for a uniprocessor system (single CPU). Processes in these simulations will require CPU bursts of one or more time units followed by I/O bursts of one or more time units. For simplicity’s sake, when more than one process is executing its I/O burst at the same...

  • Write a program in Java that will simulate FCFS (First Come First Serve) considering context switching...

    Write a program in Java that will simulate FCFS (First Come First Serve) considering context switching is 0. The program should compute waiting time and turnaround time of every job as well as the average waiting time and average turnaround time. Then change the context switching time to 0.4 milliseconds. Arrival time CPU Burst (in milliseconds Process 0) P2 P3 4 100 P6

  • Please help me create this CLI CPU Scheduling Simulator in java: First Come First Serve (FCFS)...

    Please help me create this CLI CPU Scheduling Simulator in java: First Come First Serve (FCFS) Round Robin (RR) Process information The process information will be read from an input file. The format is: pid arrival_time burst_time All of fields are integer type where: pid is a unique numeric process ID arrival_time is the time when the task arrives in the unit of milliseconds burst_time the is the CPU time requested by a task, in the unit of milliseconds The...

  • 4. Consider a ready queue with four processes :- Process Arrival Time Burst Time (ms) P1...

    4. Consider a ready queue with four processes :- Process Arrival Time Burst Time (ms) P1 Priority P2 P3 P4 P5 For each of the following CPU scheduling algorithms, determine the turnaround and average waiting time for each of the process :- a. Shortest remaining Time First b. Shortest Job First C. Priority Scheduling (Both pre-emptive and non-preemptive) d. Round Robin (quantum is 1 ms)

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT