Skip to content

Instantly share code, notes, and snippets.

@znz
Created October 16, 2013 14:05
Show Gist options
  • Select an option

  • Save znz/7008298 to your computer and use it in GitHub Desktop.

Select an option

Save znz/7008298 to your computer and use it in GitHub Desktop.
setrlimit example
% ruby -v setrlimit.rb
ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-linux]
setrlimit.rb:14: warning: assigned but unused variable - s
Process::RLIMIT_RSS = 5
Process.getrlimit(Process::RLIMIT_RSS) => [18446744073709551615, 18446744073709551615]
Process::RLIMIT_AS = 9
Process.getrlimit(Process::RLIMIT_AS) => [18446744073709551615, 18446744073709551615]
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 15860
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 1024
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) 15860
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
Process.getrlimit(Process::RLIMIT_RSS) => [18446744073709551615, 18446744073709551615]
Process.getrlimit(Process::RLIMIT_AS) => [52428800, 52428800]
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 15860
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 1024
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) 15860
virtual memory (kbytes, -v) 51200
file locks (-x) unlimited
setrlimit.rb:14:in `*': failed to allocate memory (NoMemoryError)
from setrlimit.rb:14:in `<main>'
% ruby -v setrlimit.rb
ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin12.4.1]
setrlimit.rb:14: warning: assigned but unused variable - s
Process::RLIMIT_RSS = 5
Process.getrlimit(Process::RLIMIT_RSS) => [9223372036854775807, 9223372036854775807]
Process::RLIMIT_AS = 5
Process.getrlimit(Process::RLIMIT_AS) => [9223372036854775807, 9223372036854775807]
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
file size (blocks, -f) unlimited
max locked memory (kbytes, -l) unlimited
max memory size (kbytes, -m) unlimited
open files (-n) 256
pipe size (512 bytes, -p) 1
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) 709
virtual memory (kbytes, -v) unlimited
Process.getrlimit(Process::RLIMIT_RSS) => [52428800, 52428800]
Process.getrlimit(Process::RLIMIT_AS) => [52428800, 52428800]
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
file size (blocks, -f) unlimited
max locked memory (kbytes, -l) unlimited
max memory size (kbytes, -m) 51200
open files (-n) 256
pipe size (512 bytes, -p) 1
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) 709
virtual memory (kbytes, -v) 51200
[:RLIMIT_RSS, :RLIMIT_AS].each do |sym|
n = Process.const_get(sym)
puts "Process::#{sym} = #{n}"
puts "Process.getrlimit(Process::#{sym}) => #{Process.getrlimit(n)}"
end
system("bash", "-c", "ulimit -a")
#Process.setrlimit(Process::RLIMIT_RSS, 1024*1024*50)
Process.setrlimit(Process::RLIMIT_AS, 1024*1024*50)
[:RLIMIT_RSS, :RLIMIT_AS].each do |sym|
n = Process.const_get(sym)
puts "Process.getrlimit(Process::#{sym}) => #{Process.getrlimit(n)}"
end
system("bash", "-c", "ulimit -a")
s = "1"*1024*1024*500
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment