0

Whenever i run CPU/RAM intensive tasks, i cant use my computer it freezes until the task is complete. I was looking for a way to limit resources per process for all processes.

i.e so none of the processes pass above 25% CPU or 3gb RAM.

Thanks

3
  • I take it you are on a single-core CPU? Dec 23, 2015 at 5:02
  • quad core i3 cpu Dec 23, 2015 at 6:18
  • In that case, a single busy task should not lock other threads/processes, and even if the task were massively multi-threaded, linux timeslices between active processes (using a scheduler) so everyone gets a turn, as it were. Priorities for processes are given by what is called niceness, which may be the best solution for your issue. I recommend you look up nice and renice'ing. That said, the behavior you describe concerns me in that I'm not certain the issue is CPU usage per se. If you do want to limit arbitrary processes, look at cyberciti.biz/faq/cpu-usage-limiter-for-linux Dec 23, 2015 at 6:26

1 Answer 1

1

Limiting all processes to an arbitrary limit might not be as beneficial as you might initially think.

As a comment pointed out, you can limit the CPU, but depending on the process, you might better be served by simply setting the nice-ness of the process (also known as process priority). Doing this will allow the process to run at full speed when you're just reading a site and not using any CPU, but yield and give way to your browser once it needs to start utilizing the CPU(s) for any JavaScript (as an example).

Another option is to set the CPU affinity of the process. This lets the OS only run the process on one specific CPU core, leaving the other 3 (in your case) free for anything else that might need it. This is nice when your process is a single-threaded process (like a video encoding process or source building process, for example); you can set the affinity to the 1st CPU core and you've got 3 others at idle (until used that is).

And there's also ulimit, which you can use to set soft and hard limits or RAM/CPU (though this is system wide and not per process).

It should be noted that limiting your RAM might have unintended consequences (like swap usage), and instead you should try the nice value, CPU affinity or ulimit for CPU time before limiting the RAM. RAM is not like CPU in that more usage of it will degrade overall system performance; on the contrary, system performance tends to increase when more RAM can be used and you should only notice a performance decrease if swap area has to be used over RAM (since swap is usually disk based and orders of magnitude slower than RAM), and if you notice a lot of swap area being used with a bunch of free RAM, then there's something else going on that needs to be addressed (like a kernel setting).

Hope that can help.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .