THINK FIRST·CODE LATER

← All labs

Multilevel feedback queue simulator

Problem

Simulate an MLFQ with three queues:

  • Q0: quantum q0, Q1: quantum q1, Q2: FCFS (runs a job to completion).
  • New jobs enter the tail of Q0 (in input order when several arrive at the same time).
  • When the CPU is free, it takes the first job of the highest non-empty queue and runs it for its level's quantum (or until it finishes). No preemption in the middle of a slice.
  • After the slice, first add jobs that arrived up to the end of the slice to Q0, then, if the job did not finish, move it to the tail of the next lower queue (Q2 stays Q2).
  • If all queues are empty, the CPU is idle until the next arrival.

Input: first line q0 q1; then name arrival burst per line.

Output: Gantt: with segments name(Qk) start-end (and idle s-e), then per job in input order name: finish F, turnaround T, final queue Qk (the queue it was in when it finished), then Average turnaround: x.xx.

Input:

2 4
batch 0 12
edit1 1 1
sim 3 7
edit2 5 2

Output:

Gantt: | batch(Q0) 0-2 | edit1(Q0) 2-3 | sim(Q0) 3-5 | edit2(Q0) 5-7 | batch(Q1) 7-11 | sim(Q1) 11-15 | batch(Q2) 15-21 | sim(Q2) 21-22 |
batch: finish 21, turnaround 21, final queue Q2
edit1: finish 3, turnaround 2, final queue Q0
sim: finish 22, turnaround 19, final queue Q2
edit2: finish 7, turnaround 2, final queue Q0
Average turnaround: 11.00

Data for this lab

Your program reads its data from standard input. Download the file, then give it to your program as shown below. Start with data set 1: its expected output is given.

os4-4-data-1.txt

2 4
batch 0 12
edit1 1 1
sim 3 7
edit2 5 2
What your program must print for os4-4-data-1.txt
Gantt: | batch(Q0) 0-2 | edit1(Q0) 2-3 | sim(Q0) 3-5 | edit2(Q0) 5-7 | batch(Q1) 7-11 | sim(Q1) 11-15 | batch(Q2) 15-21 | sim(Q2) 21-22 |
batch: finish 21, turnaround 21, final queue Q2
edit1: finish 3, turnaround 2, final queue Q0
sim: finish 22, turnaround 19, final queue Q2
edit2: finish 7, turnaround 2, final queue Q0
Average turnaround: 11.00

Run your program first, then open this and compare line by line: your output must contain these lines exactly.

How to give the file to my program

Terminal (macOS, Linux, or Windows Command Prompt), after compiling:

java Main < os4-4-data-1.txt

Windows PowerShell does not understand <:

Get-Content os4-4-data-1.txt | java Main

IntelliJ IDEA: Run → Edit Configurations → Redirect input from. Or simply paste the content of the file into the console when the program waits for input.

Write it here or in your IDE, then paste it. Compile and test it yourself before comparing. Your code stays in your browser — it is never sent to or stored on the server.