How do I automatically kill processes that leak memory?
Solution 1:
I would create a simple script which would filter process any process with a resident memory size (or perhaps total vm size, so including any paged out pages) bigger than a threshold that I define (depending on the amount of process, total memory available and perhaps also CPU availability). One can use a bit of bash script with either top
or ps
to dig out the list of process and memory size.
From this filtered list, I would use the leaks
command (see man 1 leaks) per process PID. If the total amount of leaked memory reported by the command is higher than yet another threshold, I would then kill and respawn it.
NOTE: You should take care not to kill any OS/System processes without knowing what you do. To avoid this situation, you should perhaps filter out the list using a "white list" approach.
Solution 2:
ulimit on most platforms does not work as expected.
If this is not a desktop app, run the offender with a proper process supervisor such as https://github.com/arya/bluepill
If this is a desktop app, contact the app developers. Feedback is necessary and important.
The UX on the OOM killer GUI for Mac is horrible. It should be biggest sorted descending with a proportional bar graph for each processes' ram usage. Furthermore, it should automatically SIGCONT all paused processes when resolved.