0

My application works fine for most inputs, but some input files make it allocate more and more memory at some point, until it is killed by the system's oom killer.

The application takes multiple hours to run, so babysitting it and manually interrupting it when its memory usage starts to break out is not an option.

I tried running the application with valgrind's massif, but since it gets killed by the system, it never produces an output file.

Is there an option to make massif write its snapshots to disk immediately?

Massif does seem to produce an output file for the application when interrupted by SIGINT, so this would probably work. Is there another tool that sends SIGINT to a process that consumes more than a certain amount of memory?

aqtth
  • 21
  • 2
  • not directly answering your question, see here how to detect low memory cases before it is too late. https://stackoverflow.com/questions/11922085/detecting-memory-running-low-before-allocations-start-failing-on-windows – nivpeled Jul 17 '19 at 06:48
  • 1
    Thank you for the comment. That would be a possibility. I could just let the program terminate gracefully with `std::exit(0)` when it allocates too much memory using new. Then massif should write its output file. – aqtth Jul 17 '19 at 06:51
  • Investigating further, I noticed that the default new handler throws `std::bad_alloc`, but my program does not throw this exception, but gets killed with `SIGKILL` by the system. So terminating using the new handler does not seem to be an option. I'm on Linux btw, the answer you cited seems to be for Windows. – aqtth Jul 17 '19 at 07:09

0 Answers0