Resource Limits

Share:

Description

Get and set RLIMIT values of the current process.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
rlimit_as(hardlim = NULL, softlim = hardlim, pid = 0, verbose = FALSE)

rlimit_core(hardlim = NULL, softlim = hardlim, pid = 0, verbose = FALSE)

rlimit_cpu(hardlim = NULL, softlim = hardlim, pid = 0, verbose = FALSE)

rlimit_data(hardlim = NULL, softlim = hardlim, pid = 0, verbose = FALSE)

rlimit_fsize(hardlim = NULL, softlim = hardlim, pid = 0,
  verbose = FALSE)

rlimit_memlock(hardlim = NULL, softlim = hardlim, pid = 0,
  verbose = FALSE)

rlimit_msgqueue(hardlim = NULL, softlim = hardlim, pid = 0,
  verbose = FALSE)

rlimit_nice(hardlim = NULL, softlim = hardlim, pid = 0, verbose = FALSE)

rlimit_nofile(hardlim = NULL, softlim = hardlim, pid = 0,
  verbose = FALSE)

rlimit_nproc(hardlim = NULL, softlim = hardlim, pid = 0,
  verbose = FALSE)

rlimit_rtprio(hardlim = NULL, softlim = hardlim, pid = 0,
  verbose = FALSE)

rlimit_rttime(hardlim = NULL, softlim = hardlim, pid = 0,
  verbose = FALSE)

rlimit_sigpending(hardlim = NULL, softlim = hardlim, pid = 0,
  verbose = FALSE)

rlimit_stack(hardlim = NULL, softlim = hardlim, pid = 0,
  verbose = FALSE)

Arguments

hardlim

hard limit in bytes

softlim

soft limit in bytes.

pid

id of the target process.

verbose

print some C output (TRUE/FALSE)

References

Jeroen Ooms (2013). The RAppArmor Package: Enforcing Security Policies in R Using Dynamic Sandboxing on Linux. Journal of Statistical Software, 55(7), 1-34. http://www.jstatsoft.org/v55/i07/.

Ubuntu Manpage: getrlimit, setrlimit - get/set resource limits. http://manpages.ubuntu.com/manpages/precise/man2/getrlimit.2.html.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
## Not run: 
#load lib
library(RAppArmor)

#current limit
rlimit_as();

#set hard limit
rlimit_as(1e9);

#set separate hard and soft limit. 
rlimit_as(1e9, 1e8);

#soft limits can be elevated
rlimit_as(soft = 1e7);
rlimit_as(soft = 1e9);

#set other limits
rlimit_core(1e9);
rlimit_data(1e9);
rlimit_fsize(1e9);
rlimit_memlock(10000);
rlimit_msgqueue(1e5);
rlimit_nofile(10);
rlimit_nproc(100);
rlimit_rttime(1e9);
rlimit_sigpending(1e4);
rlimit_stack(1000);
rlimit_cpu(60);

## End(Not run)
## Not run: testfun <- function(){
  Sys.sleep(3);
  repeat{
    svd(matrix(rnorm(1e6,1e3)));
  }
};
#will be killed after 8 seconds (3s idle, 5s CPU):
system.time(eval.secure(testfun(), RLIMIT_CPU=5));

#will be killed after 5 seconds
system.time(eval.secure(testfun(), timeout=5));
## End(Not run)