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