Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm using a background service that leaks memory from time to time. To prevent using the Alt+SysRq REISUB[1], I'd like to restrict the RAM usage for one process or a system user.

I really would like to say: User x may use the maximum amount of RAM of 1 GB.

Is this feasible? Do I need kind of virtual machine for this? I'm using Ubuntu 9.10.

share|improve this question

2 Answers 2

up vote 7 down vote accepted

ulimit is your friend. Check out the -m flag. I think you set this before you launch your process and it applies from then on (in the current shell).

share|improve this answer
    
Thanks, nice hint! As I understand ulimit, it limits all users memory/process/whatever consumption. I just like to limit it to one user/process & subprocesses. –  guerda Nov 5 '09 at 21:52
1  
ulimit is a shell command, and only affects processes started from the same shell after ulimit is executed. You startup the process in a shell script with a ulimit command to have it affect just that process. –  KeithB Nov 6 '09 at 1:52
    
Thanks, that will help! –  guerda Nov 6 '09 at 7:58

In addition to the shell commands ulimit (for bash) or limit (for csh), you can control this from inside your code with the ulimit() function.

share|improve this answer
1  
Obligatory manpages: linux.die.net/man/1/ulimit (shell command) and linux.die.net/man/3/ulimit (C function). –  Stephan202 Nov 5 '09 at 21:34

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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