So I have 4 GB RAM + 4GB swap. I want to create a user with limited ram and swap: 3 GB RAM and 1 GB swap. Is such thing possible? Is it possible to start applications with limited RAM and swap avaliable to them without creating a separate user (and not installing any special apps - having just a default Debian/CentOS server configuration, and not using sudo)?Update:So I opened terminall and typed into it ulimit command: ulimit -v 1000000 which shall be like 976,6Mb limitation. Next I called ulimit -a and saw that limitation is on. Then I started some bash script that compiles and starts my app in nohup, a long one nohup ./cloud-updater-linux.sh  >& /dev/null &... but after some time  I saw:(which would be ok if no limitations were applied - it downloaded some large lib, and started to compile it.)But I thought I applied limitations to the shell and all processes launched with/from it with ulimit -v 1000000? What did I get wrong? How to make a terminal and all sub processes it launches be limited on ram usage?
How to create a user with limited RAM usage?
users;memory;not root user;limit
ulimit is made for this.You can setup defaults for ulimit on a per user or a per group basis in /etc/security/limits.confulimit -v KBYTES sets max virtual memory size.  I don't think you can give a max amount of swap.  It's just a limit on the amount of virtual memory the user can use.So you limits.conf would have the line (to a maximum of 4G of memory)luser  hard  as   4000000UPDATE - CGroupsThe limits imposed by ulimit and limits.conf is per process.  I definitely wasn't clear on that point.If you want to limit the total amount of memory a users uses (which is what you asked).  You want to use cgroups.In /etc/cgconfig.conf:group memlimit {    memory {        memory.limit_in_bytes = 4294967296;    }}This creates a cgroup that has a max memory limit of 4GiB.In /etc/cgrules.conf:luser   memory   memlimit/This will cause all processes run by luser to be run inside the memlimit cgroups created in cgconfig.conf.