hammereditor
hammereditor

Reputation: 69

Limiting the memory usage of a program in Linux

I'm new to Linux and Terminal (or whatever kind of command prompt it uses), and I want to control the amount of RAM a process can use. I already looked for hours to find an easy-t-use guide. I have a few requirements for limiting it:

  1. Multiple instances of the program will be running, but I only want to limit some of the instances.
  2. I do not want the process to crash once it exceeds the limit. I want it to use HDD page swap.
  3. The program will run under WINE, and is a .exe.

So can somebody please help with the command to limit the RAM usage on a process in Linux?

Upvotes: 3

Views: 3740

Answers (1)

Benjamin Barenblat
Benjamin Barenblat

Reputation: 1311

The fact that you’re using Wine makes no difference in this particular context, which leaves requirements 1 and 2. Requirement 2 –

I do not want the process to crash once it exceeds the limit. I want it to use HDD page swap.

– is known as limiting the resident set size or rss of the process, and it’s actually rather nontrivial to do on Linux, as is demonstrated by a question asked in 2010. You’ll need to set up Linux control groups (cgroups). Fortunately, Justin L.’s answer gives a brief rundown on how to do so. Note that

  • instead of jlebar, you should use your own Unix user name, and
  • instead of your/program, you should use wine /path/to/Windows/program.exe.

Using cgroups will also satisfy your other requirements – you can start as many instances of the program as you wish, but only those which you start with cgexec -g memory:limited will be limited.

Upvotes: 2

Related Questions