Question

implement MLFQ using C++ please preferably linked list P1 {4,24,5,73,3,31,5,27,4,33,6,43,4,64,5,19,2} P2 {18,31,19,35,11,42,18,43,19,47,18,43,17,51,19,32,10} P3 {6,18,4,21,7,19,4,16,5,29,7,21,8,22,6,24,5} P4 {17,42,19,55,20,54,17,52,15,67,12,72,

implement MLFQ using C++ please preferably linked list

P1 {4,24,5,73,3,31,5,27,4,33,6,43,4,64,5,19,2}


P2 {18,31,19,35,11,42,18,43,19,47,18,43,17,51,19,32,10}


P3 {6,18,4,21,7,19,4,16,5,29,7,21,8,22,6,24,5}


P4 {17,42,19,55,20,54,17,52,15,67,12,72,15,66,14}


P5 {5,81,4,82,5,71,3,61,5,62,4,51,3,77,4,61,3,42,5}


P6 {10,35,12,41,14,33,11,32,15,41,13,29,11}


P7 {21,51,23,53,24,61,22,31,21,43,20}


P8 {11,52,14,42,15,31,17,21,16,43,12,31,13,32,15}


will compute the overall wait times, response times, and turnaround times for each process and averages for FCFS


the processes follow {CPU, IO, CPU, IO, ...}


output should look like this


Now Running: P1
Ready Queue: Process Burst
P2 18
P3 6
P4 17
P5 5
P6 10
P7 21
P8 11

Now In I/O: Process Remaining time
[empty]

Current Time: 4

Now running: P2

Ready queue: Process Burst
P3 6
P4 17
P5 5
P6 10
P7 21
P8 11

Now in I/O: Process Remaining time
P1 24

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

for (int i-0;i < n;i++) //loop is used for Process Burst Time cin >> burstTime[i]; //ask to enter Process Burst Time for (int

waitingTime [0] 0; = //calculating waiting time waitingTime [1] for (j = 0; j 0; 1;j++) wait ingTime[i] += readyQueue[j]; //d

//function definitions int findMin(int arra[], int size) int min = arra [0], pos = 0; for (int i = 1;i < size;i++) min pos ar

sample output

nter total number of processes (maximum 20):5 Enter Process Burst Time P[2]:4 P[3]:3 P[4]:2 Process BurstTime WaitingTime Tur

Code to copy:

#include "stdafx.h"
#include <iostream>
#include <string>

using namespace std;
//function prototypes
int findMin(int[],int);
bool hasProcesses(int[],int);
//main function
int main()
{
   //declaration of process names
   //burst time
   int burstTime[20];
   int n;
   string process[20];
   int letter = 'A';

   cout << "Enter total number of processes(maximum 20):";

   cin >> n; //ask to enter a number of processes from user

   cout << "\nEnter Process Burst Time\n";

   for (int i = 0;i < n;i++) //loop is used for Process Burst Time

   {

       cout << "P[" << i + 1 << "]:";

       cin >> burstTime[i]; //ask to enter Process Burst Time

   }
   for (int j = 0; j < n; j++)
   {
       process[j] = static_cast<char>(letter);
       letter++;
   }

   //waiting time
   int waitingTime[20];

   //ready queue to store the process ready to execute
   int readyQueue[20];

   //waiting queue to store the process which are not ready to executing
   int waitQueue[20];
   string waitProcess[20];
   string readyProcess[20];
   int i = 0, j = 0, k = 0, time = 0;
   do
   {
       //based on the arrival time and burst time sorting the process order
       while (i < n)
       {

           waitQueue[j] = burstTime[i];
           waitProcess[j] = process[i];
           burstTime[i] = -1;
           j++;
           i++;
       }

       int pos = findMin(waitQueue, j);
       readyQueue[k] = waitQueue[pos];
    
       readyProcess[k] = waitProcess[pos];
       waitQueue[pos] = -1;
       time = time + readyQueue[k];
       k++;
   } while (hasProcesses(waitQueue, n));

   waitingTime[0] = 0;

   //calculating waiting time
   for (i = 1;i < n;i++)
   {
       waitingTime[i] = 0;
       for (j = 0;j < i;j++)
           waitingTime[i] += readyQueue[j];
   }

   //displaying data
   double avgWait = 0.0, avgTurn = 0.0;
   cout << "Process " << " BurstTime " << " WaitingTime " << " TurnaroundTime" << endl << endl;

   for (int i = 0;i < n;i++)
   {
       cout << readyProcess[i] << "\t\t" << readyQueue[i] << "\t" << waitingTime[i] << "\t\t"
           << waitingTime[i] + readyQueue[i] << endl;
       avgWait += waitingTime[i];
       avgTurn += waitingTime[i] + readyQueue[i];
   }
   cout << endl << "Average waiting time: " << avgWait / n;
   cout << endl << "Average turnaround time: " << avgTurn / n << endl;
   system("pause");
}//end of main


//function definitions
int findMin(int arra[], int size)
{
   int min = arra[0], pos = 0;
   for (int i = 1;i < size;i++)
       if (min > arra[i] && arra[i] != -1)
       {
           min = arra[i];
           pos = i;
       }
   return pos;
}


bool hasProcesses(int aar[], int size)
{
   bool flag = false;
   for (int i = 0;i < size;i++)
   {
       if (aar[i]!= -1)
       {
           flag = true;
           break;
       }

    
   }
   return flag;
}

Add a comment
Know the answer?
Add Answer to:
implement MLFQ using C++ please preferably linked list P1 {4,24,5,73,3,31,5,27,4,33,6,43,4,64,5,19,2} P2 {18,31,19,35,11,42,18,43,19,47,18,43,17,51,19,32,10} P3 {6,18,4,21,7,19,4,16,5,29,7,21,8,22,6,24,5} P4 {17,42,19,55,20,54,17,52,15,67,12,72,
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
  • Please answer the following question in C++ language Consider the following set of processes, with the...

    Please answer the following question in C++ language Consider the following set of processes, with the length of the CPU burst time given in milliseconds: Process            Burst Time      Priority P1. 7 5 P2 2 4 P3 11 3 P4 9 1 P5 5 3 The processes are assumed to have arrived in the order P1,P2, P3, P4, P5, all at time 0. a. Draw four Gantt charts that illustrate the execution of these processes using the following scheduling algorithms: FCFS, SJF, nonpreemptive...

  • The processes are assumed to have arrived in the order of P1, P2, P3, P4, P5, P6 and P7 all at time 0.

    Table 1 shows the list of processes and burst time for each processesTable 1 ProcessBurst TimeP113P25P323P43P531P66P714 The processes are assumed to have arrived in the order of P1, P2, P3, P4, P5, P6 and P7 all at  time 0. a)    Calculate the average waiting time when each of the below scheduling algorithm is used. Assume that a quantum 8 is being used:i.) First Come, First Server                                                                      (6 marks)ii.) Round Robin                                                                                       (6 marks)iii.) Shortest Job First, non preemptive                                                      (6 marks)

  • (C++) I need to write a priority queue(where the processes inside are listed as example: P25:2...

    (C++) I need to write a priority queue(where the processes inside are listed as example: P25:2 , 25 being a randomly assigned ID(1-50) and 2 being a randomly assigned priority number(1-10). Once the priority queue is full(10 max), it will transfer the highest priority process to a waiting queue. Once the waiting queue is full(7 max), one process(highest priority) will transfer to a ready queue where the system would perform the process in a round robin style. Once 25 processes...

  • C program Read file problem: For example, I have an input.txt file like this: q 1...

    C program Read file problem: For example, I have an input.txt file like this: q 1 tq 4 p1 10 p2 5 p3 7 p4 20 p5 17 p6 9 p7 3 p8 11 p9 15 p10 1 I want the num of q is in one array, tq is in one array, the order of process(ie,p1,p2) is in one array, and process time is in one array(process time is the number after like p1,p2). There may many q,tq,p so...

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

  • (d) Pre-emptive priority scheduling [4 marks]: Consider the following set of processes, with the length of...

    (d) Pre-emptive priority scheduling [4 marks]: Consider the following set of processes, with the length of the CPU-burst time given in milliseconds: Process Burst Priority Arrival Time P1 8 3 0 P2 3 4 1 P3 6 2 3 P4 3 1 5 P5 1 5 7 P6 3 8 14 P7 8 5 18 (d-1) Draw Gantt chart illustrating the execution of these processes using pre-emptive priority (a smaller priority number implies a higher priority) [2 marks] 00   01  ...

  • The following processes P1, P2, P3, P4 and P5 arrive at the same time (t =...

    The following processes P1, P2, P3, P4 and P5 arrive at the same time (t = 0). Establish a timeline of the process scheduling for the following scheduling algorithms while also identifying start times for each process. FCFS (first come, first serve; assume order of P1, P2, P3, P4 and P5) SJF (shortest job first) Priority iv Round Robin (quantum = 1, assume order of P1, P2, P3, P4 and P5) Determine the average waiting time for each algorithm.

  • Suppose there are 4 processes P1, P2, P3 and P4 getting to ready queue in various...

    Suppose there are 4 processes P1, P2, P3 and P4 getting to ready queue in various arrival times and with various bursts times as detailed in the table below. Using Shortest-remaining-time-first scheduling approach, find waiting time for each process and the average waiting time and provide detailed steps taken to find the answer. Using time quantum of milliseconds. Process Arrival time (ms) Burst Time (ms) P1 0 8 P2 2 3 P3 6 2 P4 9 7 Explain Peterson’s solution...

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

  • Please answer the following question in C++ language. Thank you. Please answer all the parts. The...

    Please answer the following question in C++ language. Thank you. Please answer all the parts. The following processes are being scheduled using a preemptive, round robin scheduling algorithm. Each process is assigned a numerical priority, with a higher number indicating a higher relative priority. In addition to the processes listed below, the system also has an idle task (which consumes no CPU resources and is identified as I ). This task has priority 0 and is scheduled whenever the system...

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