// 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 #include #include #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; }