Home:ALL Converter>How Limit memory usage for a single Linux process and not kill the process

How Limit memory usage for a single Linux process and not kill the process

Ask Time:2014-11-11T16:45:58         Author:Grant Chen

Json Formatter

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?

Author:Grant Chen,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/26860822/how-limit-memory-usage-for-a-single-linux-process-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
yy