Questions tagged [setrlimit]

system call included in POSIX which allows setting of limits on operating system resources like CPU, memory, files and possibly others

setrlimit() is a system call included in POSIX which allows setting of operating system limits on resources like CPU, memory, files and possibly others. The corresponding system call for reading the limits is getrlimit(). Related tags are: , , , , .

This system call was present on System V and BSD Unixes. Later it was adopted into POSIX.1. It is also present on Linux and other Unix-like systems.

POSIX.1 (IEEE Std 1003.1) setrlimit() specifies setting of these limits:

  • RLIMIT_CORE - maximum size of a core file, in bytes
  • RLIMIT_CPU - maximum amount of CPU time, in seconds, used by a process
  • RLIMIT_DATA - maximum size of a process' data segment, in bytes
  • RLIMIT_FSIZE - maximum size of a file, in bytes, that may be created by a process
  • RLIMIT_NOFILE - a number one greater than the maximum value that the system may assign to a newly-created file descriptor
  • RLIMIT_STACK - maximum size of the initial thread's stack, in bytes
  • RLIMIT_AS - maximum size of a process' total available memory, in bytes

Other systems like BSD or Linux may allow setting of additional limits.

61 questions
1
vote
0 answers

`getrlimit(RLIMIT_NICE, &rlim)` returns `rlim.rlim_cur` of `0` which is outside of the defined range?

The man-page to getrlimit(RLIMIT_NICE, &rlim) says on successful return rlim.rlim_cur (and rlim.rlim_cur) will contain a value in the range of 1 to 40 or RLIM_INFINITY (which I think is (unsigned long)-1), but instead it always contains 0 for me.…
panzi
  • 7,517
  • 5
  • 42
  • 54
1
vote
1 answer

Setting POSIX message queues RLIMIT_MSGQUEUE to unlimited from Go for a Kubernetes container

We have a library that uses POSIX message queues to pass data between processes and requires having the msgqueue kernel parameter set to unlimited, otherwise the process will return an error too many open files. Usually we view/set this using ulimit…
Greg Bray
  • 14,929
  • 12
  • 80
  • 104
1
vote
0 answers

Java JNA application crashes when system resource limit is set inside main()

I have a JNA application that needs to compute the sum of elements in a large 1D array (~1G). Using the JNA Resource.Rlimit class I am able to increase the resource limit as shown in the following snippet: final Resource.Rlimit limit = new…
unbound37
  • 109
  • 6
1
vote
1 answer

How can I see the number of maximum open files in PHP?

With PHP I'm running into failed to open stream: Too many open files errors, thru wp-cli as well as through fpm-php. I've adapted things like fpm's rlimit and ulimit on the command line. Now it would be really nice if I can see the maximum number of…
the
  • 21,007
  • 11
  • 68
  • 101
1
vote
1 answer

Why setrlimit(RLIMIT_NPROC) doesn't work when run as root but works fine when run as a normal user?

I wrote the following C program to limit the maximum processes this program can create (on Linux). This program uses setrlimit(), and it is expected that this program can create at most 4 processes. // nproc.c #include #include…
wtz
  • 426
  • 4
  • 15
1
vote
1 answer

Limiting child process's memory usage with rlimit without affecting current process

I want to limit the memory usage of a child process using rlimit. Currently our code is as follows: old_rlimit := get_rlimit() set_rlimit(child_process_rlimit) cmd.Start() set_rlimit(old_rlimit) cmd.Wait() However, sometimes Golang runtime will…
lz96
  • 2,816
  • 2
  • 28
  • 46
1
vote
1 answer

setrlimit doesn't work on restricting the maximum amount of memory

I am learning linux resource control using setrlimit and getrlimit. The idea is to limit the maximum amount of memory that can be used for a given process: #include #include #include #include
Jes
  • 2,614
  • 4
  • 25
  • 45
1
vote
0 answers

Restricting memory using Process::setrlimit doesn't work

I want to restrict memory usage in my test, so I tested the behavior of Process::setrlimit first, and it confuses me. Here is my code: require 'securerandom' Process.setrlimit(:AS, 2 << 20) # 2MB total memory, on Mac OS X Process.setrlimit(:RSS,…
Aetherus
  • 8,720
  • 1
  • 22
  • 36
1
vote
0 answers

setting low rlimit_nproc value doesn't allow even a single fork

I am trying to use setrlimit to limit the number of processes a program can create. Here is my code: struct rlimit limiter; getrlimit( RLIMIT_NPROC, &limiter ); limiter.rlim_max = limiter.rlim_cur = 10; setrlimit( RLIMIT_NPROC, &limiter ); int val…
rohan013
  • 199
  • 1
  • 1
  • 14
1
vote
0 answers

PHP setrlimit error with Paypal IPN data capture script

So I have an IPN data capture script that has been working fine for months. No problems at all. Recently I added an email function to send my customers emails. Those emails worked great for about 15-20 days or so. I catch on that orders are not…
Jonathan
  • 11
  • 1
1
vote
2 answers

Some Linux error messages not being redirected to file with 2>x

I have a sandbox program which uses setrlimit() to limit the output file size of another program run under its control, which I run like so: sandbox -max 2048 /usr/bin/mono --debug myprogram.exe r1 2>r2 The "-max 2048" switch tells the sandbox…
user1636349
  • 458
  • 1
  • 4
  • 21
1
vote
2 answers

set stack size for threads using setrlimit

I'm using a library which creates a pthread using the default stack size of 8MB. Is it possible to programatically reduce the stack size of the thread the library creates? I tried using setrlimit(RLIMIT_STACK...) inside my main() function, but…
philipdotdev
  • 381
  • 3
  • 13
1
vote
1 answer

What unit is used in python’s resource RLIMIT_FSIZE setting

According to the docs, with Python you can set the file size limit with: resource.setrlimit(resource.RLIMIT_FSIZE,(fileseeklimit,fileseeklimit)) but it is not clear what the unit is here. The Bash builtin ulimit uses kilobytes for everything.
Joachim Breitner
  • 25,395
  • 6
  • 78
  • 139
1
vote
1 answer

Apache 2.4 hits rlimit_nproc: hidden processes?

My webapp allows users to execute some arbitrary code in a sandbox. To prevent forkbombs, the application calls setrlimit and limits RLIMIT_NPROC to 50 before executing user code. This worked great in Ubuntu 12.04 up till Ubuntu 13.04. However,…
Jeroen Ooms
  • 31,998
  • 35
  • 134
  • 207
1
vote
0 answers

set a process open file max to maximum (in linux)

Is there anyway to set the (hard limit) open-file-max (setrlimit, RLIMIT_NOFILE) to the maximum? suppose that the pid of the process is zero (root). I just want to increase the RLIMIT_NOFILE to the maximum, but I don't know what is the maximum…
cinsk
  • 1,576
  • 2
  • 12
  • 14