Simulate an MLFQ with three queues:
- Q0: quantum
q0, Q1: quantumq1, 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