Process.setrlimit
static VALUE
proc_setrlimit(int argc, VALUE *argv, VALUE obj)
{
VALUE resource, rlim_cur, rlim_max;
struct rlimit rlim;
rb_check_arity(argc, 2, 3);
resource = argv[0];
rlim_cur = argv[1];
if (argc < 3 || NIL_P(rlim_max = argv[2]))
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;
}
Sets limits for the current process for the given resource to cur_limit (soft limit) and max_limit (hard limit); returns nil.
Argument resource specifies the resource whose limits are to be set; the argument may be given as a symbol, as a string, or as a constant beginning with Process::RLIMIT_ (e.g., :CORE, 'CORE', or Process::RLIMIT_CORE.
The resources available and supported are system-dependent, and may include (here expressed as symbols):
-
:AS: Total available memory (bytes) (SUSv3, NetBSD, FreeBSD, OpenBSD except 4.4BSD-Lite). -
:CORE: Core size (bytes) (SUSv3). -
:CPU: CPU time (seconds) (SUSv3). -
:DATA:Datasegment (bytes) (SUSv3). -
:FSIZE:Filesize (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:Filedescriptors (number) (SUSv3). -
:NPROC: Number of processes for the user (number) (4.4BSD, GNU/Linux). -
:NPTS: Number of pseudo terminals (number) (FreeBSD). -
: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).
Arguments cur_limit and max_limit may be:
-
Integers (
max_limitshould not be smaller thancur_limit). -
Symbol:SAVED_MAX, string'SAVED_MAX', or constantProcess::RLIM_SAVED_MAX: saved maximum limit. -
Symbol:SAVED_CUR, string'SAVED_CUR', or constantProcess::RLIM_SAVED_CUR: saved current limit. -
Symbol:INFINITY, string'INFINITY', or constantProcess::RLIM_INFINITY: no limit on resource.
This 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])
Not available on all platforms.