THINK FIRST·CODE LATER

← All labs

Working sets and thrashing detection

Problem

Input: delta frames nProc, then one line of page references per process (all lines have the same length; at each time step every process makes one reference).

For each time t = 1 … n, compute each process's working set (distinct pages among its last delta references, up to t) and the total demand D. Print:

t=7: P0[1,2,3,4]=4 P1[10,11,12,13]=4 | D=8 > 7 THRASHING RISK

(sets sorted, without spaces; the suffix > frames THRASHING RISK only when D > frames). Then Peak demand D at t=T, frames F, overloaded steps K (first time the peak is reached) and either Advice: suspend Pi (working set s) to free frames — the process with the largest working set at the peak time (lowest index on ties) — if the peak exceeds the frames, or Advice: all working sets fit.

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.

os10-3-data-1.txt

4 7 2
1 2 3 1 2 3 4 5 6 7 4 5
10 10 11 11 10 12 13 14 15 16 13 14
What your program must print for os10-3-data-1.txt
t=6: P0[1,2,3]=3 P1[10,11,12]=3 | D=6
t=7: P0[1,2,3,4]=4 P1[10,11,12,13]=4 | D=8 > 7 THRASHING RISK
t=8: P0[2,3,4,5]=4 P1[10,12,13,14]=4 | D=8 > 7 THRASHING RISK

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 < os10-3-data-1.txt

Windows PowerShell does not understand <:

Get-Content os10-3-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.