using System; using System.IO; using System.Diagnostics; namespace OSProgram3 { class Program { static int Main(string[] args) { if (args.Length < 1) { Console.WriteLine("No input file specified in command line arguments."); Console.ReadLine(); return 1; } string filename1 = args[0]; int numRows = GetRows(filename1); Console.WriteLine("Returned Rows = " + numRows); int numCols = GetCols(filename1); Console.WriteLine("Returned Cols = " + numCols); Console.WriteLine("Getting Process Array."); int[,] procArr = GetProcArr(filename1, numRows, numCols); PrintProcArr(procArr, numRows, numCols); //now implement FCFS scehduling on 1 CPU GoFCFS(procArr); Console.WriteLine("Press Enter to Exit Program."); Console.ReadLine(); return 0; } //end main //take filename and return number of rows (processes) static int GetRows(string filename) { int rows = 0; StreamReader sr = new StreamReader(filename); while (sr.ReadLine() != null) { rows++; //Console.WriteLine(rows); } //Console.WriteLine("\nRows = " + rows); sr.Close(); return rows; } //take filename and return number of columns (process attributes) static int GetCols(string filename) { int cols = 1; StreamReader sr = new StreamReader(filename); string line = sr.ReadLine(); for (int i=0; i procArr[row, 1]) { Console.WriteLine("Doing Process #" + (row+1) ); resArr[row, 0] = stw.ElapsedMilliseconds - procArr[row, 1]; resArr[row, 1] = DoBusyWork(procArr[row, 2], stw) + resArr[row, 0]; row++; } //else wait for submission time (go to next iteration, check time again) } //end while stw.Stop(); Console.WriteLine("Done Scheduling FCFS."); //now analyze the results AnalyzeRes(resArr, "FCFS"); } //end GoFCFS() //Busy work method to simulate process static long DoBusyWork(int time, Stopwatch stw) { long burstStart = stw.ElapsedMilliseconds; while ( (stw.ElapsedMilliseconds - burstStart) < time) { //waste time //Console.WriteLine("Wasting time."); } return (stw.ElapsedMilliseconds - burstStart); } //end DoBusyWork() //Analyze a results array static void AnalyzeRes(long[,] resArr, string alg) { long totalWait = 0; long totalTurn = 0; int numProcs = resArr.GetLength(0); Console.WriteLine("Analyzing " + alg); for (int i=0; i