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

Set time limit to a child process

I'm creating a shell and have a problem when creating my own ulimit function : I want to limit the time of a process, and I use setrlimit for it. But it seems that when I call execvp then, the time limit is kind of erased. In this example code, when…
MeanStreet
  • 1,217
  • 1
  • 15
  • 33
3
votes
2 answers

Is it possible to have millisecond precision with setrlimit in c

As the title suggests i need to know if there is some way to have less then second precision with the setrlimit RLIMIT_CPU ? struct rlimit cpulimit; cpulimit.rlim_cur = 5; // 5 seconds SIGXCPU cpulimit.rlim_max = 5; // 5 seconds SIGKILL ( I know…
Ext
  • 657
  • 1
  • 8
  • 13
3
votes
1 answer

Changing file descriptor limit in C (OSX)

I want to increase the maximum number of file descriptors available to my C program, which is running on OSX 10.7. I've added the following code to my project, but it fails! struct rlimit limit; if(getrlimit(RLIMIT_NOFILE, &limit)) { …
charliehorse55
  • 1,940
  • 5
  • 24
  • 38
2
votes
2 answers

Can setrlimit be used to enforce resource usage limits over periods of time?

I want to set limits for how long programs spawned by execv can use a certain amount of memory and a certain amount of CPU time. For example, I want to set limits like a program cannot exceed 100MB for 30 seconds, and a program cannot use 90% or…
node ninja
  • 31,796
  • 59
  • 166
  • 254
2
votes
0 answers

Forking when setrlimit was already set to 0?

I'm preparing a script to evaluate some code coming from other people, hence, I need to limit the execution environment as much as I can. The script is developed under python3.4 using psutil and subprocess, the target file to run is a compiled c++…
user2905333
  • 35
  • 1
  • 5
2
votes
1 answer

Limiting the core file size

I am trying to truncate the core file size for my application. I tried using setrlimit() function but no luck. Observations: I set rlim_cur = 270 which is 270 * 1024 = 276480 bytes, and if core file is less than 276480 bytes only then the core file…
klekle
  • 81
  • 1
  • 5
2
votes
2 answers

Is there a way to limit the number of R processes running

I use the doMC that uses the package multicore. It happened (several times) that when I was debugging (in the console) it went sideways and fork-bombed. Does R have the setrlimit() syscall? In pyhton for this i would use resource.RLIMIT_NPROC…
statquant
  • 13,672
  • 21
  • 91
  • 162
2
votes
2 answers

prevent java program from opening threads

I'm trying to run a java application , more specifically a jar compiled one, using execve() in c something like that: char *cmd[] = {"a.jar"}; execve("a.jar",cmd,NULL); that is working OK but when I try to limit the number of threads that this…
Ali Kanaan
  • 45
  • 7
2
votes
1 answer

What is the correct definition of RLIMIT_NPROC?

I'm taking a look at the implementation of the Android exploit Rage Against The Cage. The idea behind it is that it creates as many processes as necessary to reach RLIMIT_NPROC for the shell UID so that the next time the Android Debug Bridge (ADB)…
freitass
  • 6,542
  • 5
  • 40
  • 44
2
votes
1 answer

setrlimit() not affecting spawned std::threads

I am currently working on a pipeline which loads and transforms multiple images at once. As this is happening to many images at the same time (1440) the memory footprint is quite heavy. I therefore tried to implement a memory management system based…
Jan Stephan
  • 403
  • 3
  • 11
2
votes
0 answers

Anonymous mmap and data segment size

I've been under the impression that since Unix systems introduced anonymous mmap's, RLIMIT_DATA has been somewhat useless, as mmap address space isn't included in the data segment size. In particular, the glibc malloc() implementation uses anonymous…
janneb
  • 36,249
  • 2
  • 81
  • 97
2
votes
1 answer

Limiting the memory usage of a program in Linux

I'm new to Linux and Terminal (or whatever kind of command prompt it uses), and I want to control the amount of RAM a process can use. I already looked for hours to find an easy-t-use guide. I have a few requirements for limiting it: Multiple…
hammereditor
  • 39
  • 1
  • 4
2
votes
0 answers

Limiting memory usage for a single process in OSX /Darwin

I am trying to modify some JNI code to limit the amount of memory that a process can consume. Here is the code that I am using to test setRlimit on linux and osx. In linux it works as expected and the buf is null. This code sets the limit to 32 MB…
Chris Hinshaw
  • 6,967
  • 2
  • 39
  • 65
2
votes
2 answers

setrlimit isn't reliable?

I'm trying to use setrlimit() to cap the amount of time a process takes. However it doesn't seem to work when I do certain operations like printf(). Here is a test program illustrating the problem: #include #include int…
tskuzzy
  • 35,812
  • 14
  • 73
  • 140
1
vote
1 answer

How OS handles stack growth of multiple threads with option "ulimit -s unlimited"?

By default, linux stack size is limited to 8 MB. So in case of multi-threaded environment each thread will get its own 8 MB stack. If any thread wanders off the bottom of a stack into the guard page will be rewarded with a segmentation-fault signal.…