Unformatted text preview:

Matt Ramsay & Robert Brown CS 470 Process Management Project 2/15/02 • File: main.cpp • Commented Code: /*********************************** ** Matthew Ramsay | Robert Brown ** ** CS470 Inst: Dr. Deborah Hwang ** ** Process Management Program ** ** 2/14/02 ** ***********************************/ #include <iostream.h> #include <stdio.h> #include <stdlib.h> #include <vector> #include <fstream.h> #include "pmpclass.h" using namespace std; /************************** ** Function Prototypes ** **************************/ vector<process*> Delete(vector<process*> DeleteQ, int ID); vector<process*> DeleteW(vector<process*> DeleteWQ, int IDW); /**************** ** Main Code ** ****************/ int main(int argc, char* argv[]) { /*** Check amount of arguments: <Filename><inputfile><quantum#> ***/ if (argc != 3) { cout << "You schmuck! This program was hard enough to write, you can at least call it correctly!\n"; exit(1); }/*** Dynamic Vector Creation ***/ vector<process*> ReadyQ; vector<process*> WaitQ; ifstream in; /*** Input variables ***/ char option; int n,b,p; char *q = argv[2]; int quantum = atoi(q); /*** Temporary variables ***/ int temp,waitID; process * tempProcess = NULL; process * tempP = NULL; /*** Open file ***/ in.open(argv[1]); /*** Main loop code ***/ while(1) { in >> option; // Take in first command from input file if(in.eof()) exit(1); switch(option) { /********************************************************************* If first command is C then input pid and burst. Then: - Make sure queue is not empty, else assign pid to process. - Push the process on the Queue - Std output of process on Ready Queue - Std output of process Running *********************************************************************/ case 'C' : case 'c' : { in >> n; in >> b; if(ReadyQ.empty())p = 0; else p = ReadyQ[0]->id; cout << option << " " << n << " " << b << " " << p << endl; ReadyQ.push_back(new process(n,b,p,quantum)); tempProcess = ReadyQ.back(); cout << "PID " << tempProcess->id << " " << tempProcess->burst << " put on Ready Queue" << endl; if(ReadyQ.size() == 0) cout << "Process 0 running" << endl; else { cout << "PID " << ReadyQ[0]->id << " " << ReadyQ[0]->burst << " running with " << ReadyQ[0]->activeTime << " left" << endl; temp = ReadyQ[0]->burst; temp--; ReadyQ[0]->burst = temp; temp = ReadyQ[0]->activeTime; temp--; ReadyQ[0]->activeTime = temp; } // endELSE for std output break; } // endCASE 'C' /********************************************************************* If first command is D then input pid. Then: - Make sure queue is not empty. - Run Delete Function to check both queue - Std output of process Running *********************************************************************/ case 'D' : case 'd' : { in >> n; cout << option << " " << n << endl; if(ReadyQ.size() != 0) { ReadyQ = Delete(ReadyQ,n); WaitQ = DeleteW(WaitQ,n); } // endIF for Delete functionif(ReadyQ.size() == 0) cout << "Process 0 running" << endl; else { cout << "PID " << ReadyQ[0]->id << " " << ReadyQ[0]->burst << " running with " << ReadyQ[0]->activeTime << " left" << endl; temp = ReadyQ[0]->burst; temp--; ReadyQ[0]->burst = temp; temp = ReadyQ[0]->activeTime; temp--; ReadyQ[0]->activeTime = temp; } // endELSE for std output break; } // endCASE 'D' /********************************************************************* If first command is I then process interrupt. Then: - Std output of process Running *********************************************************************/ case 'I' : case 'i' : { cout << option << endl; if(ReadyQ.size() == 0) cout << "Process 0 running" << endl; else { cout << "PID " << ReadyQ[0]->id << " " << ReadyQ[0]->burst << " running with " << ReadyQ[0]->activeTime << " left" << endl; temp = ReadyQ[0]->burst; temp--; ReadyQ[0]->burst = temp; temp = ReadyQ[0]->activeTime; temp--; ReadyQ[0]->activeTime = temp; } // endELSE for std output break; } // endCASE 'I' /********************************************************************* If first command is W then input event number. Then:- Std output of process on Wait Queue - Move process to temp then push to Wait Queue - Std output of process Running *********************************************************************/ case 'W' : case 'w' : { in >> n; cout << option << " " << n << endl; cout << "PID " << ReadyQ[0]->id << " " << ReadyQ[0]->burst << " placed on wait queue" << endl; /*Reassign quantum and event numbers */ ReadyQ[0]->waitNumber = n; ReadyQ[0]->activeTime = quantum; /* Move process to temp */ tempP = ReadyQ[0]; ReadyQ.erase(ReadyQ.begin()); WaitQ.push_back(tempP); if(ReadyQ.size() == 0) cout << "Process 0 running" << endl; else { cout << "PID " << ReadyQ[0]->id << " " << ReadyQ[0]->burst << " running with " << ReadyQ[0]->activeTime << " left" << endl; temp = ReadyQ[0]->burst; temp--; ReadyQ[0]->burst = temp; temp = ReadyQ[0]->activeTime; temp--; ReadyQ[0]->activeTime = temp; } // endELSE for std output break; } // endCASE 'W' /********************************************************************* If first command is E then input event number to return to. Then: - Std output of process Running - Std output of process placed on Ready Queue


View Full Document
Download NOTES
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view NOTES and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view NOTES 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?