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
1 answer

limit number of forks/child procs

I am hosting a computing service on Ubuntu 12.04 and I need a method to prevent users from forkbombing. I am currently using setrlimit(RLIMIT_NPROC) in Linux. However, this actually sets a global limit on the number of processes for a given UID.…
Jeroen Ooms
  • 31,998
  • 35
  • 134
  • 207
1
vote
1 answer

Why is RLIMIT_NOFILE rlim_max of -1 on BSD?

In the following code: 139 struct rlimit limit; 140 141 method = "rlimit"; 142 if (getrlimit(RLIMIT_NOFILE, &limit) < 0) { 143 perror("calling getrlimit"); 144 exit(1); 145 } 146 147 /* set the current to the…
Aeonaut
  • 1,267
  • 3
  • 14
  • 18
0
votes
1 answer

What does a hard limit of -1 mean (getrlimit for RLIMIT_STACK)?

I see a segfault with a multi threaded application and want to play around with the resource limits. However when I try to get current stack limit using the code below, I see that the hard limit is -1. What does that mean? How do I fix it? // Get…
0
votes
0 answers

Restrict system call

I have tried to restrict fork system call and allow thread system by using Setrlimit, nproc, but fork and thread both are not allowed by using Setrlimit. So I have come to know using seccomp but still same issue. Even seccomp also works same as…
0
votes
0 answers

Playwright not opening browser on subprocess

I'm trying to use playwright python and restrict its memory using a subprocess using the following code: # scrapper.py from playwright.sync_api import sync_playwright if __name__ == '__main__': with sync_playwright() as p: browser =…
itepifanio
  • 572
  • 5
  • 16
0
votes
0 answers

Can setrlimit be used to force mmap to return VA within 64GB range?

I am working on a ARM64 server and trying to make an old program work. I don't have to source code, just a binary. The binary uses a LuaJit which does not support 48bit Virtual Address(VA). However, my kernel uses 48bit VA. LuaJit uses mmap to…
DeanSinaean
  • 2,297
  • 4
  • 16
  • 19
0
votes
2 answers

What would be the best way to set limits on unknown code?

I'm using a Python library (SimpleParse) that I seem to be causing some runaway recursion with it. It's already crashed my computer once when I was just trying to debug it. What would be the best way for me to set some limits on how much memory…
supercheetah
  • 3,200
  • 4
  • 25
  • 38
0
votes
1 answer

java.lang.OutOfMemoryError: requested 16 bytes for CHeapObj-new. Out of swap space?

I got this error on trying to get the Java search process UP(start a java process). I am setting the address space using the RLIMIT_AS. Please help me to get past this error. I have doubts about the VM Arguements. (See below). Is there any way to…
Rajath
  • 215
  • 5
  • 13
0
votes
0 answers

I used RLIMIT_RSS to limit my program's RES, but it didn't work

When I want to use struct rlimit to limit my program's memory, but RLIMIT_RSS didn't work. I set my RSS limit is 100 MiB.But when my test program used about 700 MiB, it still continue; This is my Code. int load_limit_config(const Limitlist *CFG) { …
hehe HE
  • 21
  • 1
0
votes
1 answer

Limit CPU usage of a Python Bottle webserver

I'm using Python + Bottle as a webserver. As I use the production server for many other websites, I don't want Python + Bottle to eat 70% of the CPU for example. How is it possible to limit the CPU usage of a Python Bottle webserver? I was thinking…
Basj
  • 41,386
  • 99
  • 383
  • 673
0
votes
0 answers

Resource manager class in C++

I am currently implementing a server program that forks a process to handle a client's request. The forked process must be well-controlled in terms of cpu, memory, disk, and other system attributes. I noticed the easiest way to implement a resource…
Jes
  • 2,614
  • 4
  • 25
  • 45
0
votes
0 answers

OpenMP crash when Using setrlimit

I have one process in Linux server, am setting 1gb virtual memory for that process using setrlimit() function and openmp is used in the code base. During execution process got crashed, core file is generated. I have debugged the core file and…
Srinu
  • 1
  • 1
0
votes
1 answer

Python on OSx - set the new limit of open files

I want to set a new limit of possible open files with the command: import resource resource.setrlimit(RLIMIT_NOFILE, (resource.RLIM_INFINITY, resource.RLIM_INFINITY)) However, I'm getting an error: ValueError: current limit exceeds maximum…
Ziva
  • 3,181
  • 15
  • 48
  • 80
0
votes
0 answers

Cancelling ulimit bounds

I am writing isolated sandbox for untrusted code so I am looking for safe way to isolate code execution. Also I need a way to collect code stats (memory usage, cpu usage, etc.) I have tried Docker but Stats API can stream only with a second period…
Nikita Lapkov
  • 121
  • 1
  • 6
0
votes
1 answer

printf makes setrlimit not working

Following this SO question and this answer in particular, it seems that calling setrlimit after a printf make it not working. Here is the example code: #include #include int main() { struct rlimit rlp; FILE…
Kevin MOLCARD
  • 2,168
  • 3
  • 22
  • 35