How Limit memory usage for a single Linux process and not kill the process.
I know ulimit can limit memory usage, but if exceed the limit, will kill the process.
Is there any other command or shell can limit memory usage and not kill the process?
Paulo Fidalgo :
Another way besides setrlimit, which can be set using the ulimit utility:\n\n$ ulimit -Sv 500000 # Set ~500 mb limit\n\nis to use Linux's control groups, because it limits a process's (or group of processes') allocation of physical memory distinctly from virtual memory. For example:\n\n\n $ cgcreate -g memory:/myGroup\n $ echo $(( 500 * 1024 * 1024 )) > /sys/fs/cgroup/memory/myGroup/memory.limit_in_bytes\n $ echo $(( 5000 * 1024 * 1024 )) > /sys/fs/cgroup/memory/myGroupmemory.memsw.limit_in_bytes\n\n\nwill create a control group named \"myGroup\", cap the set of processes run under myGroup up to 500 MB of physical memory and up to 5000 MB of swap. To run a process under the control group:\n\n\n $ cgexec -g memory:myGroup COMMAND\n\n\nNote: For what I can understand setrlimit will limit the virtual memory, although with cgroups you can limit the physical memory.",
2014-11-11T08:59:18