How to limit OS runtime resources on linux? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5

How to limit OS runtime resources on linux?

There is a server with linux (let's say Ubuntu), and there are lots of users (100 or maybe more). So, I want to limit each user to use only: 200MB of RAM and 20second of process time (max). I already did this for the storage thing with Quotas, but I'm not sure what approach is correct when it comes to processes and runtime resources. Any help is appreciated.

5th Apr 2018, 6:16 AM
Aaron Sarkissian
Aaron Sarkissian - avatar
8 Answers
+ 7
Did you try using 'ulimit'? I guess it's for the current session only but is helpful. It provides control over the resources available to the shell and to processes started by it, only on systems that allow such control. Check these links out, – https://ss64.com/bash/ulimit.htmlhttps://www.ibm.com/support/knowledgecenter/en/SSYKE2_7.0.0/com.ibm.java.lnx.70.doc/user/ulimits.html
5th Apr 2018, 6:30 AM
Dev
Dev - avatar
+ 4
De͏͏v Great, I'll try this out.
5th Apr 2018, 6:46 AM
Aaron Sarkissian
Aaron Sarkissian - avatar
+ 3
If CPanel, use Shell Fork Bomb Protection to set a ulimit. Also a good firewall like CSF/LFD will alert you when users exceed a cert virtual memory limit or number of processes. It can be configured to kill these if desired as well.
5th Apr 2018, 9:34 AM
ScriptKittie
ScriptKittie - avatar
+ 3
Kayla Armstrong No I'm not using any panel. Right now I'm testing it on my own rig with Ubuntu 16. If my idea works well, I'll host it on AWS or smth similar. But thanks again, I'll try the ulimit as Dev suggested too.
5th Apr 2018, 11:21 AM
Aaron Sarkissian
Aaron Sarkissian - avatar
+ 2
Aaron Erhardt I have a server and the users are accessing it via SSH. But I don't want any user to run CPU/RAM heavy process and eat up all the resources. For example, if a user wants to run an infinite loop, the system should block the process after 20 seconds. Or if the code os eating up all the RAM, again the process should be terminated of it exceed the limit.
5th Apr 2018, 6:44 AM
Aaron Sarkissian
Aaron Sarkissian - avatar
+ 2
Oh cool, regarding process time, if they’re using php, set max_execution_time in php.ini. Definitely look into firewalls, though. They’ll alert you to anything using more resources than a sane standard.
5th Apr 2018, 1:51 PM
ScriptKittie
ScriptKittie - avatar
+ 1
Also, you should be able to limit your users resource allocation. Are you using any panel?
5th Apr 2018, 9:36 AM
ScriptKittie
ScriptKittie - avatar
0
Usually you use or virtual machines (or docker container) to limit a users RAM and CPU time.
5th Apr 2018, 6:26 AM
Aaron Eberhardt
Aaron Eberhardt - avatar