S
S
Schoolboy.2015-11-01 21:54:19
linux
Schoolboy., 2015-11-01 21:54:19

How to limit process RAM by PID?

I heard about cgroup but did not find a command anywhere to limit the memory of a process.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
O
Oleg Tsilyurik, 2015-11-01
@Olej

You can try changing the RAM limit in the limits of the shell instance you are running the program from... see:

$ ulimit -Sm
unlimited

This requires LXC containers.
Are you ready to take such a complicated path for such a simple goal?
Perhaps something will tell you the translation of a whole series of articles directly from the author of LXC: LXC 1.0

M
Michael, 2015-11-01
@Singaporian

You need CGroups.
ulimit works fine and doesn't really work.

J
jcmvbkbc, 2015-11-02
@jcmvbkbc

A couple of links on the topic about modern ways of manipulating groups in different distributions:
https://wiki.archlinux.org/index.php/Cgroups
https://www.digitalocean.com/community/tutorials/h...
Hardcore way with manual adding a group (memory:/test), limiting the memory in it (one megabyte) and moving the process ($PID) into it:

# mkdir /sys/fs/cgroup/memory/test
# echo 1048576 > /sys/fs/cgroup/memory/test/memory.limit_in_bytes
# echo $PID >  /sys/fs/cgroup/memory/test/tasks

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question