Question: Im doing a FCFS CPU scheduler simulation below is the code i have so far, im having problems with the processes in the I/O queue

Im doing a FCFS CPU scheduler simulation below is the code i have so far, im having problems with the processes in the I/O queue i need to arrange them based on arrival time and it crashes before finishing all the processes. NOTE: you do not to use my code as long as any other piece of code is in C++, Please let me know if you can help with this assignment.

C++ (First Come First Served) *****FCFS non preemptive***** All processes have an arrival time of 0, that will change as the process do their CPU Burst for the first time. In which case they should be arranged in order of arrival in the I/O queue.Let me know if you need more information.

Process Data: process goes {CPU burst, I/O time, CPU burst, I/O time, CPU burst, I/O time,.., last CPU burst} P1 { 4, 15, 5, 31, 6, 26, 7, 24, 6, 41, 4, 51, 5, 16, 4}

P2 { 9, 28, 11, 22, 15, 21, 12, 28, 8, 34, 11, 34, 9, 29, 10, 31, 7}

P3 { 24, 28, 12, 21, 6, 27, 17, 21, 11, 54, 22, 31, 18}

P4 { 15, 35, 14, 41, 16, 45, 18, 51, 14, 61, 13, 54, 16, 61, 15}

P5 { 6, 22, 5, 21, 15, 31, 4, 26, 7, 31, 4, 18, 6, 21, 10, 33, 3}

P6 { 22, 38, 27, 41, 25, 29, 11, 26, 19, 32, 18, 22, 6, 26, 6}

P7 { 4, 36, 7, 31, 6, 32, 5, 41, 4, 42, 7, 39, 6, 33, 5, 34, 6, 21, 9}

P8 { 5, 14, 4, 33, 6, 31, 4, 31, 6, 27, 5, 21, 4, 19, 6, 11, 6}

.

Example of Output (not exact results this is just the format) Current Time: 0

Now running: P1 ..................................................

Ready Queue: Process Burst P2 9 P3 24 P4 15 P5 6 P6 22 P7 4 P8 5 ..................................................

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

:::::::::::::::::::::::::::::::::::::::::::::::::: . . .

Current Time: 705

Now running: P6 ..................................................

Ready Queue: Process Burst [empty] ..................................................

Now in I/O: Process Remaining I/O time [empty] ..................................................

Completed: P1, P2, P3, P4, P5, P7, P8

::::::::::::::::::::::::::::::::::::::::::::::::::

Current Time: 711

Now running: [idle] ..................................................

Ready Queue: Process Burst [empty] ..................................................

Now in I/O: Process Remaining I/O time P6 26 ..................................................

Completed: P1, P2, P3, P4, P5, P7, P8

::::::::::::::::::::::::::::::::::::::::::::::::::

Current Time: 737

Now running: P6 ..................................................

Ready Queue: Process Burst [empty] ..................................................

Now in I/O: Process Remaining I/O time [empty] ..................................................

Completed: P1, P2, P3, P4, P5, P7, P8

::::::::::::::::::::::::::::::::::::::::::::::::::

Current Time: 743

Now running: [idle] ..................................................

Ready Queue: Process Burst [empty] ..................................................

Now in I/O: Process Remaining I/O time [empty] ..................................................

Completed: P1, P2, P3, P4, P5, P6, P7, P8

::::::::::::::::::::::::::::::::::::::::::::::::::

Finished

Total Time: 743 CPU Utilization: 89.2328%

Waiting Times P1 P2 P3 P4 P5 P6 P7 P8 43 105 373 178 122 395 98 85 Average Wait: 174.875

Turnaround Times P1 P2 P3 P4 P5 P6 P7 P8 288 424 665 647 385 743 466 318 Average Turnaround: 492

Response Times P1 P2 P3 P4 P5 P6 P7 P8 0 24 343 37 13 225 4 8 Average Response: 81.75

.

#include #include #include #include using namespace std;

/* * */ int main() { int ps[9][19] = { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 4, 15, 5, 31, 6, 26, 7, 24, 6, 41, 4, 51, 5, 16, 4, 0, 0, 0, 0 }, // p1 { 9, 28, 11, 22, 15, 21, 12, 28, 8, 34, 11, 34, 9, 29, 10, 31, 7, 0, 0 }, // p2 { 24, 28, 12, 21, 6, 27, 17, 21, 11, 54, 22, 31, 18, 0, 0, 0, 0, 0, 0 }, // p3 { 15, 35, 14, 41, 16, 45, 18, 51, 14, 61, 13, 54, 16, 61, 15, 0, 0, 0, 0 }, // p4 { 6, 22, 5, 21, 15, 31, 4, 26, 7, 31, 4, 18, 6, 21, 10, 33, 3, 0, 0 }, // p5 { 22, 38, 27, 41, 25, 29, 11, 26, 19, 32, 18, 22, 6, 26, 6, 0, 0, 0, 0 }, // p6 { 4, 36, 7, 31, 6, 32, 5, 41, 4, 42, 7, 39, 6, 33, 5, 34, 6, 21, 9 }, // p7 { 5, 14, 4, 33, 6, 31, 4, 31, 6, 27, 5, 21, 4, 19, 6, 11, 6, 0, 0 } }; // p8

deque burst[9], iotime[9], remainio[9];

// init burst and iotime for (int i = 0; i < 9; i++) { for (int j = 0; j < 19; j = j + 2) { if (ps[i][j] != 0) { burst[i].push_back(ps[i][j]); iotime[i].push_back(ps[i][j + 1]); remainio[i].push_back(ps[i][j + 1]); } } } // process in ready queue and io queue deque ready, io; for (int i = 1; i < 9; i++) { ready.push_back(i); } int currTime = 0; int currBurst = 0; int passTime = 0; int running; // running process int runningBurst = 0; // burst of running process int runningIO; // iotime of runnign process

int count = 0; while (ready.size() != 0 || io.size() != 0) { cout << "Current Time: " << currTime << endl; // Get a running process from ready queue running = ready.front(); ready.pop_front(); if (burst[running].size() != 0){ // Get burstime runningBurst = burst[running].front(); burst[running].pop_front(); }

if (iotime[running].size() != 0){ // Get iotime runningIO = iotime[running].front(); iotime[running].pop_front(); }

// Shown running process cout << " Now running: P" << running << endl; cout << ".................................................. " << endl;

// Show the other queue in ready with burst time cout << "Ready Queue: Process Burst" << endl;

for (int i = 0; i < ready.size(); i++) { int rp = ready.at(i); //cout << "Debug:" << rp << endl;

int burstTime = burst[rp].front(); cout << " P" << rp << " " << burstTime << endl; }

// Show IO queue cout << "Now in I/O: Process Remaining I/O time" << endl; if (io.size() == 0) cout << " [empty]" << endl; else { for (int i = 0; i < io.size(); i++) { int iop = io.at(i); int remainTime = remainio[iop].front(); // cout << " P" << iop << " " << remainTime << endl; } }

// update ready queue, io queue // for each process in io queue, update remain time // if remain time is < 0, push new process in ready

int size = io.size(); for (int i = 0; i < size; i++) { int iop = io.front(); io.pop_front(); int remainTime = remainio[iop].front(); remainio[iop].pop_front();// remainTime -= runningBurst;

if (remainTime > 0) // still in io queue { io.push_back(iop); remainio[iop].push_front(remainTime); } else // push new process in ready { ready.push_back(iop); } } cout << " .................................................." << endl; cout << ".................................................. " << endl; // push running process to I/O queue io.push_back(running);

// update current time currTime += runningBurst; }

cout << "Total Time: " << currTime << endl; cout << "CPU Utiliation: " << endl;

cout << "Waiting Times: " << endl; cout << "Turnaround Times: " << endl;

cout << "Average Turnaround: " << endl;

cout << "Response Times: " << endl;

cout << "Average Response: " << endl; return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!