CPU Time Limits

Blinkenshell has for a long time employed CPU time limits via ulimit. The limit is currently set so that no process can use more than 60 minutes of CPU time, or it will be killed. This is ofcourse to stop rampant processes in the system (a process is killed after using 100% for one hour), and it has worked pretty well for some time. There is however one problem with this solution, namely long-running processes like irssi etc. These processes doesn’t use much CPU, but over weeks or months it amounts up to something significant.

Since upgrading to a new kernel, the measurements of CPU times seems to have changed, and some processes in the system (top 3 is all weechat-curses for some reason…) are already very close to the 60 min limit and will be killed off soon. I’ve decided to try a new approach to this problem now, where I do not set any limit of CPU time at all. Instead there is a program which monitors the runnnig processes and the CPU time they’ve used during the last 10 minutes, and calculates % CPU usage during that time period. If a process seems to use very much CPU during this time, the process will be reniced to a lower priority. The idea is if this heavy CPU use goes on for a long enough time, the process will be killed. This will however not interfere with long-running processes since they don’t have a heavy CPU load during the measurement period of 10 minutes.

The ulimits are set when you log in, so any sessions you have from before I changed this will still have the old limit, and all processes started from these sessions will have the same old limit. This includes screen sessions! You will have to log out and then back in, and restart any screens, to get the new limit applied. You can check your current CPU limit (in seconds) with this command: ulimit -t You don’t have to do this ofcourse, but if your irssi is killed of it might be a good idea so it doesn’t happen again.

Also, the program handling this is still not very well tested and might need some work before everything works as intended. It will currently not kill any processes at all, just renice.

This entry was posted in linux, shell. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *