Method: Process#setrlimit
- Defined in:
- process.c
#setrlimit(resource, cur_limit, max_limit = cur_limit) ⇒ nil (private)
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: 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). -
: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.
5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 |
# File 'process.c', line 5676
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;
}
|