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
13
votes
2 answers

Set stack size with setrlimit() and provoke a stack overflow/segfault

In the given example below I try to set the stacksize to 1kb. Why is it now possible to allocate an array of ints on the stack with size 8kb in foo() ? #include #include void foo(void); int main() { struct rlimit lim =…
tur1ng
  • 3,139
  • 5
  • 24
  • 31
13
votes
1 answer

POSIX rlimit: What exactly can we assume about RLIMIT_DATA?

Prequisites POSIX.1 2008 specifies the setrlimit() and getrlimit() functions. Various constants are provided for the resource argument, some of which are reproduced below for easier understaning of my question. The following resources are…
fuz
  • 88,405
  • 25
  • 200
  • 352
12
votes
2 answers

How can I limit memory acquired with `malloc()` without also limiting stack?

I'm trying to keep student code from running wild with allocations and dragging my test machine to a halt. I've tried setrlimit(RLIMIT_DATA, r); where r is a struct holding the limits. But unfortunately although this limit stops brk and sbrk from…
Norman Ramsey
  • 198,648
  • 61
  • 360
  • 533
11
votes
2 answers

Set stack size programmatically on Windows

Is it possible in WinAPI to set stack size for the current thread at runtime like setrlimit does on Linux? I mean to increase the reserved stack size for the current thread if it is too small for the current requirements. This is in a library that…
Serge Rogatch
  • 13,865
  • 7
  • 86
  • 158
10
votes
1 answer

How do I use `setrlimit` to limit memory usage? RLIMIT_AS kills too soon; RLIMIT_DATA, RLIMIT_RSS, RLIMIT_STACK kill not at all

I'm trying to use setrlimit to limit my memory usage on a Linux system, in order to stop my process from crashing the machine (my code was crashing nodes on a high performance cluster, because a bug led to memory consumption in excess of 100 GiB). …
gerrit
  • 24,025
  • 17
  • 97
  • 170
10
votes
1 answer

Resource limits on Windows?

What are the Windows equivalents to the resource limit mechanisms exposed on Unix systems by Python's resource module, and POSIX setrlimit? Specifically, I'm limiting processor time for a child process to several seconds. If it hasn't completed…
Matt Joiner
  • 112,946
  • 110
  • 377
  • 526
9
votes
2 answers

Processes resources not limited by setrlimit

I wrote a simple program to restrict it's data size to 65Kb and to verify the same i am allocating a dummy memory of more than 65Kb and logically if i am doing all correct (as below) malloc call should fail, isn't it? #include…
pa1
  • 778
  • 3
  • 11
  • 26
8
votes
2 answers

Closing opened file descriptors in child process

Is there a way to iterate through already open file descriptors (opened by parent process) and close them one by one in child process? OS: Unix. Reason for closure: RLIMIT_NOFILE limit of the setrlimit() constrains the number of file descriptors…
learner
  • 128
  • 1
  • 9
7
votes
4 answers

Find current number of open filehandle ( NOT lsof )

On *NIX systems, is there a way to find out how many open filehandles are there in the current running process? I am looking for an API or a formula for use in C, from within the running process in question.
ϹοδεMεδιϲ
  • 2,790
  • 3
  • 33
  • 54
5
votes
1 answer

Is it reasonable to expect that in Linux, fd < maximum number of open file descriptors?

I'm writing a server that needs to handle many open sockets, so I use setrlimit() to set the maximum number of open file descriptors (as root, before dropping privileges) like so: #include #define MAX_FD_C 9001 if (setrlimit( …
Will
  • 2,014
  • 2
  • 19
  • 42
4
votes
3 answers

How does OS honor user limits configured in /etc/security/limits.conf since setrlimit is process based?

I noted that in /etc/security/limits.conf, the limits are configured on a per user basis (or per group basis), for example: @faculty hard nproc 50 I assume that it is setrlimit that does the work to set limits, but setrlimit…
wangshuaijie
  • 1,821
  • 3
  • 21
  • 37
4
votes
0 answers

SIGXCPU raised by setrlimit RLIMIT_CPU later than expected in a virtual machine

[EDIT: added MCVE in the text, clarifications] I have the following program that sets RLIMIT_CPU to 2 seconds using setrlimit() and catches the signal. RLIMIT_CPU limits CPU time. «When the process reaches the soft limit, it is sent a SIGXCPU…
CristianCantoro
  • 722
  • 1
  • 7
  • 17
4
votes
1 answer

which is better way to edit RLIMIT_NPROC value

My application creates per connection thread . Application is ruinng under the non-zero user id and Sometimes number of threads surpasses default value 1024 . I want to edit this number so I have few options run as root [very bad idea and also have…
Akaks
  • 461
  • 3
  • 21
4
votes
2 answers

Python on MacOS totally ignoring rlimit

My Python process on MacOS is totally ignoring the rlimits below which I set. (I confirmed by print that they have been set) Physical memory usage goes above 2.4Gb, at which point CPU usage falls << 5% and it hangs. (The underlying culprit seems to…
smci
  • 32,567
  • 20
  • 113
  • 146
3
votes
1 answer

RLIMIT_AS is not working upon setting its soft limit to a certain value

For a process, I have set a soft limit value of 335544320 and hard limit value of 1610612736 for the resource RLIMIT_AS. Even after setting this value, the address space of the process goes up to maximum 178MB. But I am able to see the value of the…
Rajath
  • 31
  • 1
  • 2
1
2 3 4 5