Question

I would like to limit memory used by a process started through bash with the ulimit command on Linux. I was wondering what OS mechanism is used to support ulimit. In particular, is it based on cgroups?

Was it helpful?

Solution

The Linux API methods for getting and setting limits are getrlimit(2) and setrlimit(2)

Limits are managed within the process space. A child process will inherit the limits of its parent. Limits are part of the POSIX standard, so all POSIX compliant operating systems support them (Linux, BSD, OSX).

cgroups are Linux specific, and are not even required in a Linux install. I'm not sure if it is possible to manage limits with cgroups, but it would definitely be non-standard do to so.

OTHER TIPS

"ulimit" is basically an anachronism. You shouldn't have any real limits out of the box if you need the resources, and there are better ways to establish quotes if you want to limit resources.

Here's a good overview:

Several man pages to look at include:

I use softlimit, part of DJB's daemontools package.

By specifying something like softlimit -m 1048576 nautilus for example, the program (nautilus) will never exceed 1MiB of memory usage (which also causes it to fail immediately in this case).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top