Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I want a First come first served schduler simulation in C that uses a a ready qu

ID: 3707451 • Letter: I

Question

I want a First come first served schduler simulation in C that uses a a ready queue. Basically process enter the ready queue one by one ( different arrivial times) and the output would be something like shown below.

FCFS Scheduling**** t=0 CPU: Loading process 0 (CPU burst-10) Ready queue: 1 CPU:Running process 0 (remaining CPU burst- 5) Ready queue: 1-2-3 t-10 CPU:Finishing process 0: loading process1 (CPU burst3) Ready queue: 2-3-4 t- 15 CPU : Running process 2 (remaining CPU burst = 5) Ready queue: 3-4

Explanation / Answer

int main()

{

//Ids of process

int processes[] = { 1, 2, 3 , 4};

int totalTime = 0;

int n = sizeof processes / sizeof processes[0];

//Burst time of all processes ids

int burst_time[] = {10, 5, 5, 5};

// calculate the total time required

for(int i = 0; i < n ; i++){

totalTime = totalTime + burst_time[i];

}

int k = 0;

  

int waitingTime[n];

int turnaround[n];

  

waitingTime[0] = 0;

  

//calculate waiting time

for (int i = 1; i < n ; i++ )

waitingTime[i] = burst_time[i-1] + waitingTime[i-1] ;

//calculate turn arount time

for (int i = 0; i < n ; i++)

turnaround[i] = burst_time[i] + waitingTime[i];

  

// print the desired output as required

for(int j = 1 ;j < totalTime ;j++){

if (j % 5 == 0) {

cout << "t = " << j << endl;

if ( burst_time[k] > j) {

cout << "Loading process " << k << endl;

k++;

}

else if ( burst_time[k] == j || burst_time[k-1] == j) {

cout << "Finishing process " << k << " Loading process " << k+1 <<endl;

k++;

}

else{

cout << "Running process " << k + 1 << endl;

k++;

}

}

}

  

  

//print the process details in queue

for (int i=0; i<n; i++)

{

cout << " " << i+1 << " " << burst_time[i] <<" "

<< waitingTime[i] <<" " << turnaround[i] <<endl;

}

return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote