1) Perform a hand simulation (draw a pitcure) of the mfq simulation lab to ensur
ID: 664957 • Letter: 1
Question
1) Perform a hand simulation (draw a pitcure) of the mfq simulation lab to ensure that you understand the algorithm. Your output should agree with the partial output provided in the lab document.
2) In this lab you will write a Java program that will simulate an operating system’s job scheduling policy to determine which process will be assigned the CPU when it becomes available. We will utilize a system of queues to simulate a sophisticated job scheduling mechanism, the multi-level feedback queue (MFQ)
Here are materials on what to use for this lab below.
- The input to this simulation will consist of job requests, each composed of three elements:
Arrival time – Time job is initially submitted to the pattern
Process identifier (pid) – Identifies each process as it travels through the system
CPU time – CPU time required by the process to complete its job
- The output, displayed in a tabular format, should include a table entry each time a job enters the system indicating the:
Event
System time
Processor identifier (pid)
CPU time needed
- When a process a completes and leaves the system, an appropriate table entry should be output to the indicate:
Event
System time
Process identifier (pid)
Total time in the system
Identify of the lowest- level queue in which the process resided
- When the simulation is complete, you should also output the following:
Total number of jobs
Total time of all jobs in system – sum of the time each job is in the system
Average response time – where response time is defines as the interval from the time a process enters the system to the time of first response, or the time it starts running
Average turnaround time for the jobs – where turnaround time is defined as the interval from the time a process enters the system to the time of its completion
Average waiting time – where waiting is the amount of time that a process is kept waiting in a queue
Average throughout for the system as a whole – the number of jobs divided by the sum of total time of all jobs in the system
Total CPU idle time – time the CPU has no jobs to run
- Be sure that your program sends all output to a file called csis.txt. This output file will be submitted along with our source code for the lab.
- Be sure all your data is properly labeled and all average values are displayed to two decimal places.
- Here is the data set which your program should run on, put these numbers in mfq.txt (text file created from filewriter):
2 101 3
7 102 1
9 103 7
12 104 5
14 105 1
17 106 1
18 107 50
24 108 2
34 109 12
37 110 3
44 111 10
45 112 48
50 113 1
56 114 1
71 115 3
81 116 2
-Here are the first couple of lines of output and the last couple of lines of output that your program should generate
Lab Notes 1: Classes
You should have total of six classes in this lab:
Driver Job MFQ CPU ObjectQueue ObjectQueueInterface
The Job class include these class variables:
The CPU class include these class variables:
Use this Driver class
// Driver Class Java
Import java.io*;
public class Driver
{
publice static void(String [ ] args) throws IOException
{
PrintWriter pw = new PrintWriter(new FileWriter(“csis.txt”));
MFQ mfq = new MFQ(pw);
mfw.getJobs();
mfw.outputHeader();
mfw.runSimulation();
mfw.outStats();
pw.close();
}
}
Lab Notes 2 – Input Queue
- Along with the four queues that you will be using for this lab, I would also recommend creating an input queue. Before the lab simulation begins, read each line of input from mfq.txt, insert data into a newly created Job object, and then insert the Job object at the front of the queue to determine whether or not it’s time for the Job object at the front of the input queue to determine whether or not it’s time for the Job object to enter the simulation, i.e., is the system time equal to the arrival time of the Job object at the front of the queue?
Lab Notes 3 - String Class Split Method to Parse Strings
- When reading in data from a file on a line-by-line basis, we often have the need to parse(i.e., divide up) the string to extract the individual pieces of information. The queue lab requires that you read the mfq.txt input file that contains three integers per line to grab each of the three integers on the line.
- We can use Scanner class to reach each line from the input file
- You could use then use the StringTokenizer class to parse each line read from the input file. However, the StringTokenizer class is losing favor to the split() method found in the String class.
Here is a diagram as well
Explanation / Answer
// programming the SJF scheduling algorithm import java.util.*; public class SJF { public static void main(String[] args) { Scanner input = new Scanner(System.in); int index = 1; ArrayList tasks = new ArrayList(); // storage for tasks while (input.hasNextInt()) // read CPU burst times of tasks { int burst = input.nextInt(); // create a new task tasks.add(new Task(index, burst)); // and add it to an array index++; } int numTasks = tasks.size(); // total number of tasks Task[] tasksA = tasks.toArray(new Task[tasks.size()]); // convert ArrayList Comparator c = new Comparator() // into array { public int compare(Task t1, Task t2) // comparator for sorting { return(t1.burst - t2.burst); } }; Arrays.sort(tasksA, c); // sort tasks by burst times System.out.println(numTasks + " created"); // print the schedule int waitingTime = 0; int time = 0; System.out.print("0"); for (int i=0; iRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.