My computer sometimes freezes because some process starts to read huge amounts of data from the hard disk. I want to find out what process does this.
The tool must:
- Add one line to a given text file every second
- That line must contain:
- The name (for instance "virtualbox" or "/usr/lib/firefox/firefox -new-window" or something similar) of the program that has read the most data from the hard disk (I only have one hard disk) during that second
- A timestamp, without which I can not know whether the reads happened before or during the freeze.
- If possible, the quantity of data read by that program during that second (for instance "17899 blocks" or "2 MB/s" or something similar)
- It must run even if the computer is running super slowly:
- Not start any new process, because in these near-freeze conditions starting a new process (even a very tiny one) takes a very long time. That means no bash script calling
ps
every second. - Be efficient. If possible, not compute statistics for all processes and then throw all but the first one.
- Write directly to disk, because when these freezes happen the only thing I can do is wait an hour, reboot the computer, then read that text file to investigate on the cause of the crash.
- Not start any new process, because in these near-freeze conditions starting a new process (even a very tiny one) takes a very long time. That means no bash script calling
I will run the program as root with high priority.