12

Occasionally some processes on my GNU/Linux desktop (such as gv and gnash) use up the physical memory and cause thrashing. Since these processes aren't important, I want them to be automatically killed if they use too much memory.

I think the /etc/security/limits.conf file and the -v option could be used for this. The question is whether it limits the amount of available memory per process of a particular user, or the sum for all the processes of a user. Also I would like to ask how to make change to that file in effect without rebooting.

11

There's also the ulimit mechanism. There's a system call (in Linux, it's a C library function) ulimit(3) and a Bash builtin ulimit. Type ulimit -a to see all the things you can limit to. To see the current virtual memory limit say ulimit -v. You can set it by saying ulimit -v INTEGER-KILOBYTES.

Running ulimit changes things for your current shell, and you can only select a value smaller than the current one. To run a command with limited virtual memory, you can just use a Bash sub-shell:

( ulimit -v 131072; some-app )
| improve this answer | |
  • I found this link helpful. "Virtual memory size (-v): This option includes all types of memory that includes stack, heap, and memory-mapped files. Attempts to allocate memory in excess of this limit fails with an out-of-memory error. The value for this option is specified in kilobytes." – Andrew Jun 21 at 21:37
  • "Maximum resident set size (RSS) (-m): This option limits the amount of memory that can be swapped in to physical memory on behalf of any one process. The value for this option is specified in kilobytes." "Data segment (-d): This option limits the amount of memory that a process can allocate to a heap. The value for this option is specified in kilobytes." "Stack size (-s): This option limits the amount of memory a process can allocate to a stack. The value for this option is specified in kilobytes." – Andrew Jun 21 at 21:37
  • Personally I like doing e.g. ulimit -v 1000000 && firefox with && instead of ; to make sure ulimit succeeds first – Andrew Jun 21 at 21:45
3

limits.conf will apply to users example : oracle soft memlock 3145728 oracle hard memlock 3145728

otherwise if you re looking for a per process limit .. take a look at sysctl -a for a permanent effect .. you could add your params to sysctl.conf

good luck

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.