0

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.

womble
  • 95,029
  • 29
  • 173
  • 228
Joshua D'Alton
  • 428
  • 2
  • 13
  • 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 06:28

1 Answers1

1

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.

womble
  • 95,029
  • 29
  • 173
  • 228