2

Let's say I have two processes. One critical and one nice to have process.

Now, let's say the nice to have process starts leaking memory. How can I stop the leaking process from using up all system memory and causing the critical one to crash or slow down?

I would like that the non-critical process simply terminate or throw std::bad_alloc when it uses more memory than a certain threshold.

ronag
  • 49,529
  • 25
  • 126
  • 221
  • I guess one way would be to simply have a thread that checks the memory usage and calls `std::terminate` if it exceeds it. Though getting a `std::bad_alloc` on `new` would be a nicer solution which the process at least could try to recover from. – ronag Jun 15 '14 at 11:26

1 Answers1

0

AFAIK Windows do not support ulimit style restriction, so the next best thing may be write a watchdog program, check process's memory (and/or other resource usage) and terminate them if needed.

As a side note, I would not bet on a program to terminate itself when things already get messed.

See also: EnumProcess, GetProcessWorkingSetSize

Non-maskable Interrupt
  • 3,841
  • 1
  • 19
  • 26