Method: Process.setrlimit
- Defined in:
- process.c
.setrlimit(resource, cur_limit, max_limit) ⇒ nil .setrlimit(resource, cur_limit) ⇒ nil
Sets the resource limit of the process. cur_limit means current (soft) limit and max_limit means maximum (hard) limit.
If max_limit is not given, cur_limit is used.
resource indicates the kind of resource to limit. It should be a symbol such as :CORE, a string such as "CORE" or a constant such as Process::RLIMIT_CORE. The available resources are OS dependent. Ruby may support following resources.
- AS
-
total available memory (bytes) (SUSv3, NetBSD, FreeBSD, OpenBSD but 4.4BSD-Lite)
- CORE
-
core size (bytes) (SUSv3)
- CPU
-
CPU time (seconds) (SUSv3)
- DATA
-
data segment (bytes) (SUSv3)
- FSIZE
-
file size (bytes) (SUSv3)
- MEMLOCK
-
total size for mlock(2) (bytes) (4.4BSD, GNU/Linux)
- MSGQUEUE
-
allocation for POSIX message queues (bytes) (GNU/Linux)
- NICE
-
ceiling on process’s nice(2) value (number) (GNU/Linux)
- NOFILE
-
file descriptors (number) (SUSv3)
- NPROC
-
number of processes for the user (number) (4.4BSD, GNU/Linux)
- RSS
-
resident memory size (bytes) (4.2BSD, GNU/Linux)
- RTPRIO
-
ceiling on the process’s real-time priority (number) (GNU/Linux)
- RTTIME
-
CPU time for real-time process (us) (GNU/Linux)
- SBSIZE
-
all socket buffers (bytes) (NetBSD, FreeBSD)
- SIGPENDING
-
number of queued signals allowed (signals) (GNU/Linux)
- STACK
-
stack size (bytes) (SUSv3)
cur_limit and max_limit may be :INFINITY, "INFINITY" or Process::RLIM_INFINITY, which means that the resource is not limited. They may be Process::RLIM_SAVED_MAX, Process::RLIM_SAVED_CUR and corresponding symbols and strings too. See system setrlimit(2) manual for details.
The following example raises the soft limit of core size to the hard limit to try to make core dump possible.
Process.setrlimit(:CORE, Process.getrlimit(:CORE)[1])
4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 |
# File 'process.c', line 4802
static VALUE
proc_setrlimit(int argc, VALUE *argv, VALUE obj)
{
VALUE resource, rlim_cur, rlim_max;
struct rlimit rlim;
rb_secure(2);
rb_scan_args(argc, argv, "21", &resource, &rlim_cur, &rlim_max);
if (rlim_max == Qnil)
rlim_max = rlim_cur;
rlim.rlim_cur = rlimit_resource_value(rlim_cur);
rlim.rlim_max = rlimit_resource_value(rlim_max);
if (setrlimit(rlimit_resource_type(resource), &rlim) < 0) {
rb_sys_fail("setrlimit");
}
return Qnil;
}
|