#define RLIMIT_CORE 1 // Size of core files, 0 for disabling. #define RLIMIT_CPU 2 // CPU time limit in seconds. #define RLIMIT_FSIZE 4 // Maximum file size in bytes. #define RLIMIT_NOFILE 5 // Maximum number of open file descriptors. #define RLIMIT_STACK 6 // Maximum stack size in bytes. #define RLIMIT_AS 7 // Maximum memory size in bytes. struct ulimit { uint64_t soft; uint64_t hard; }; int rlimit(int resource, struct ulimit *new, struct ulimit *old);
This syscall fetches and sets current limits for a specified resource, hard limits can only be lowered, are inherited from parent to children, and start maxed out. Soft limits can be moved around.
The available limits are:
RLIMIT_CORE: Core files exceeding this size will be truncated, with 0,
core files are not generated.
RLIMIT_CPU: Once the limit is passed, the process is killed.
RLIMIT_FSIZE: System call growing the file fails with EFBIG.
RLIMIT_NOFILE: Adding a new file descriptor fails with EMFILE.
RLIMIT_STACK: The value is used for the size of created stacks, thus
there is no failure condition.
RLIMIT_AS: mmap or other virtual memory allocation syscalls will
fail with ENOMEM.
This syscall returns 0 on success or -1 on failure, with the
following errno:
EFAULT: One of the passed buffers was not 0 and not accessible.
EINVAL: Invalid value for resource.
EPERM: MAC did not allow the operation.