memory-and-process-scheduler

git clone git://git.codymlewis.com/memory-and-process-scheduler.git
Log | Files | Refs | README

A3.java (1801B)


      1 import java.util.LinkedList;
      2 import java.util.ArrayList;
      3 import java.util.Arrays;
      4 
      5 public class A3 {
      6     public static void main(String args[]) {
      7         if (args.length < 3) {
      8             System.err.println("Error: Not enough arguments supplied.");
      9             System.err.println("Usage: java A3 <F> <Q> <INPUT_FILES>");
     10             System.exit(1);
     11         }
     12         try {
     13             A3 runner = new A3();
     14             System.exit(
     15                 runner.run(
     16                     Integer.parseInt(args[0]),
     17                     Integer.parseInt(args[1]),
     18                     new ArrayList<String>(Arrays.asList(Arrays.copyOfRange(args, 2, args.length)))
     19                 )
     20             );
     21         } catch (Exception e) {
     22             e.printStackTrace();
     23         }
     24     }
     25 
     26     public int run(int frames, int quantum, ArrayList<String> processFiles) throws Exception {
     27         int framesPerProcess = (int) Math.floor(frames / processFiles.size());
     28         runWithPolicy(framesPerProcess, quantum, processFiles, "LRU");
     29         System.out.println("------------------------------------------------------------");
     30         System.out.println();
     31         runWithPolicy(framesPerProcess, quantum, processFiles, "Clock");
     32         return 0;
     33     }
     34 
     35     public void runWithPolicy(int framesPerProcess, int quantum,
     36             ArrayList<String> processFiles, String fbname) throws Exception {
     37         LinkedList<Process> processes = new LinkedList<Process>();
     38         for(int i = 0; i < processFiles.size(); ++i) {
     39             processes.add(new Process(i + 1, processFiles.get(i), framesPerProcess, fbname));
     40         }
     41         Scheduler scheduler = new Scheduler(processes, quantum);
     42         scheduler.run();
     43         System.out.format("%s - Fixed\n", fbname);
     44         System.out.println(scheduler.summary());
     45     }
     46 }