Servers have multiple users running multiple programs, some of which don't seem to behave and will eat up RAM like there is no tomorrow, for example:

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
30091 xxxx 20   0 2194m 1.4g 1.4g S   21  9.0   0:56.03 aaaaa
30212 xxxx 20   0 1460m 1.1g 1.1g D    5  6.9   0:44.12 aaaaa

We have filesystem quota setup, otherwise nothing else that I know of. I'd like to be able to limit VIRT RES SHR (perhaps just limiting 1 will limit the other 2?). Is this possible?

As well I would like to limit cputime before command is terminated (actually the command is called by another script, I assume the father script won't be terminated?).

I've had a look at limits.conf and PAM stuff, but not sure what is the best way, and how to test.

link|improve this question
Also, it has to be outside of limits.conf or whatever, as the users have non-interactive logins/scripts. I tested some things in limits.conf but they don't work due to this. – Joshua D'Alton Aug 15 '11 at 6:28
feedback

1 Answer

You want setrlimit(RLIMIT_AS, ...). From the manpage (setrlimit(2)):

RLIMIT_AS

The maximum size of the process's virtual memory (address space) in bytes. This limit affects calls to brk(2), mmap(2) and mremap(2), which fail with the error ENOMEM upon exceeding this limit. Also automatic stack expansion will fail (and generate a SIGSEGV that kills the process if no alternate stack has been made available via sigaltstack(2)). Since the value is a long, on machines with a 32-bit long either this limit is at most 2 GiB, or this resource is unlimited.

link|improve this answer
cool I will try that. – Joshua D'Alton Jul 25 '11 at 7:07
uhm how do I actually use that? it seems to be in C code? I needed something for limits.conf or similar? – Joshua D'Alton Aug 8 '11 at 23:53
feedback

Your Answer

 
or
required, but never shown

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