setrlimit(p1, p2, p3 = v3) public

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.

CORE

core size (bytes) (SUSv3)

CPU

CPU time (seconds) (SUSv3)

DATA

data segment (bytes) (SUSv3)

FSIZE

file size (bytes) (SUSv3)

NOFILE

file descriptors (number) (SUSv3)

STACK

stack size (bytes) (SUSv3)

AS

total available memory (bytes) (SUSv3, NetBSD, FreeBSD, OpenBSD but 4.4BSD-Lite)

MEMLOCK

total size for mlock(2) (bytes) (4.4BSD, GNU/Linux)

NPROC

number of processes for the user (number) (4.4BSD, GNU/Linux)

RSS

resident memory size (bytes) (4.2BSD, GNU/Linux)

SBSIZE

all socket buffers (bytes) (NetBSD, FreeBSD)

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 raise the soft limit of core size to the hard limit to try to make core dump possible.

Process.setrlimit(:CORE, Process.getrlimit(:CORE)[1])
Show source
Register or log in to add new notes.