Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Limit the memory and cpu available for a user in Linux

I am a little concerned with the amount of resources that I can use in a shared machine. Is there any way to test if the administrator has a limit in the amount of resources that I can use? And if does, to make a more complete question, how can I set up such limit?

like image 755
Eduardo Avatar asked Jan 12 '09 23:01

Eduardo


People also ask

How do I change memory limit in Linux?

Edit Your “memory_limit”ini file, you want to open it in your favorite text editor (vim/nano/etc.). In this example, the memory limit is set to 64MB. If you wanted to change it to 128MB or 32MB or whatever, you just need to change this line. Once you have this line set appropriately, save and exit your php.


3 Answers

For process related limits, you can have a look in /etc/security/limits.conf (read the comments in the file, use google or use man limits.conf for more information). And as jpalecek points out, you may use ulimit -a to see (and possibly modify) all such limits currently in effect.

You can use the command quota to see if a disk quota is in effect.

like image 154
matli Avatar answered Sep 21 '22 01:09

matli


You can try running

ulimit -a

to see what resource limits are in effect. Also, if you are allowed to change such limits, you can change them by the ulimit command, eg.

ulimit -c unlimited

lifts any limit for a size of a core file a process can make.

like image 38
jpalecek Avatar answered Sep 19 '22 01:09

jpalecek


At the C level, the relevant functions (actually syscalls(2)...) could be setrlimit(2) and setpriority(2) and sched_setattr(2). You probably would want them to be called from your shell.

See also proc(5) -and try cat /proc/self/limits and sched(7).

You may want to use the renice(1) command.

If you run a long-lasting program (for several hours) not requiring user interaction, you could consider using some batch processing. Some Linux systems have a batch or at command.

like image 38
Basile Starynkevitch Avatar answered Sep 17 '22 01:09

Basile Starynkevitch