I need to combine two source files to incorporate both a time sharing and i/o delay concept and am having some trouble. I need some code to spit out a log of a file in this format
Input File:
3: 1 6 3
5: 2 4 4 4
12: 3 10
CPP File 1:
// batch.cpp Dave Reed 9/10/02
//
// SIMPLE batch simulator. A collection of jobs are read in from
// a file, and then executed in order (no time sharing).
///////////////////////////////////////////////////////////////////////////////
const int LOAD_DELAY = 5; // setup time for a new job
const int IO_DELAY = 3; // time to perform I/O operation
const string JOB_FILE = "jobsIO.dat"; // file containing job data
int main()
{
JobQueue CPUjobs(JOB_FILE);
int time = 0;
while (CPUjobs.JobsRemaining()) {
int current = CPUjobs.GetCurrentID();
if (time < CPUjobs.GetCurrentStart()) {
time = CPUjobs.GetCurrentStart();
}
cout << setw(4) << time << ": LOAD JOB " << current << endl;
time += LOAD_DELAY;
cout << setw(4) << time << ": START JOB " << current << endl;
JobStatus status = OK;
while (status != DONE) {
time++;
status = CPUjobs.ExecuteCurrentJob();
if (status == IO) {
cout << setw(4) << time << ": I/O JOB " << current << endl;
time += IO_DELAY;
cout << setw(4) << time << ": RESUME JOB " << current << endl;
}
}
cout << setw(4) << time << ": FINISH JOB " << current << endl;
CPUjobs.RemoveCurrentJob();
}
cout << "DONE PROCESSING" << endl;
return 0;
}
CPP File 2:
// multi.cpp Dave Reed 9/3/02
//
// SIMPLE multiprogramming simulator. A collection of jobs are read in from
// a file, and then executed using timesharing (TIME_SLICE set as a constant).
///////////////////////////////////////////////////////////////////////////////
const int TIME_SLICE = 100; // time slice duration for time sharing
const int LOAD_DELAY = 5; // setup time for a new job
const string JOB_FILE = "jobs.dat"; // file containing job data
int main()
{
JobQueue CPUjobs(JOB_FILE);
int time = 0, slice_count = TIME_SLICE;
bool loadJob = true;
while (CPUjobs.JobsRemaining()) {
int current = CPUjobs.GetCurrentID();
if (slice_count == TIME_SLICE) {
if (loadJob) {
cout << setw(4) << time << ": LOAD JOB " << current << endl;
time += LOAD_DELAY;
loadJob = false;
}
cout << setw(4) << time << ": START JOB " << current << endl;
}
time++;
slice_count--;
JobStatus status = CPUjobs.ExecuteCurrentJob();
if (status == DONE) {
cout << setw(4) << time << ": FINISH JOB " << current << endl;
CPUjobs.RemoveCurrentJob();
slice_count = TIME_SLICE;
loadJob = true;
}
else if (slice_count == 0) {
cout << setw(4) << time << ": TIMEOUT JOB " << current << endl;
CPUjobs.InterruptCurrentJob();
I need to combine two source files to incorporate both a time sharing and i/o delay concept and am having some trouble. I need some code to spit out a log of a file in this format
Input File:
3: 1 6 3
5: 2 4 4 4
12: 3 10
CPP File 1:
// batch.cpp Dave Reed 9/10/02
//
// SIMPLE batch simulator. A collection of jobs are read in from
// a file, and then executed in order (no time sharing).
///////////////////////////////////////////////////////////////////////////////
#include <iostream>
#include <iomanip>
#include <string>
#include "JobQueue.h"
using namespace std;
const int LOAD_DELAY = 5; // setup time for a new job
const int IO_DELAY = 3; // time to perform I/O operation
const string JOB_FILE = "jobsIO.dat"; // file containing job data
int main()
{
JobQueue CPUjobs(JOB_FILE);
int time = 0;
while (CPUjobs.JobsRemaining()) {
int current = CPUjobs.GetCurrentID();
if (time < CPUjobs.GetCurrentStart()) {
time = CPUjobs.GetCurrentStart();
}
cout << setw(4) << time << ": LOAD JOB " << current << endl;
time += LOAD_DELAY;
cout << setw(4) << time << ": START JOB " << current << endl;
JobStatus status = OK;
while (status != DONE) {
time++;
status = CPUjobs.ExecuteCurrentJob();
if (status == IO) {
cout << setw(4) << time << ": I/O JOB " << current << endl;
time += IO_DELAY;
cout << setw(4) << time << ": RESUME JOB " << current << endl;
}
}
cout << setw(4) << time << ": FINISH JOB " << current << endl;
CPUjobs.RemoveCurrentJob();
}
cout << "DONE PROCESSING" << endl;
return 0;
}
CPP File 2:
// multi.cpp Dave Reed 9/3/02
//
// SIMPLE multiprogramming simulator. A collection of jobs are read in from
// a file, and then executed using timesharing (TIME_SLICE set as a constant).
///////////////////////////////////////////////////////////////////////////////
#include <iostream>
#include <iomanip>
#include <string>
#include "JobQueue.h"
using namespace std;
const int TIME_SLICE = 100; // time slice duration for time sharing
const int LOAD_DELAY = 5; // setup time for a new job
const string JOB_FILE = "jobs.dat"; // file containing job data
int main()
{
JobQueue CPUjobs(JOB_FILE);
int time = 0, slice_count = TIME_SLICE;
bool loadJob = true;
while (CPUjobs.JobsRemaining()) {
int current = CPUjobs.GetCurrentID();
if (slice_count == TIME_SLICE) {
if (loadJob) {
cout << setw(4) << time << ": LOAD JOB " << current << endl;
time += LOAD_DELAY;
loadJob = false;
}
cout << setw(4) << time << ": START JOB " << current << endl;
}
time++;
slice_count--;
JobStatus status = CPUjobs.ExecuteCurrentJob();
if (status == DONE) {
cout << setw(4) << time << ": FINISH JOB " << current << endl;
CPUjobs.RemoveCurrentJob();
slice_count = TIME_SLICE;
loadJob = true;
}
else if (slice_count == 0) {
cout << setw(4) << time << ": TIMEOUT JOB " << current << endl;
CPUjobs.InterruptCurrentJob();
slice_count = TIME_SLICE;
loadJob = (current != CPUjobs.GetCurrentID());
}
}
cout << "DONE PROCESSING" << endl;
return 0;
}
Any ideas? Thanks