# 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);
# }
# 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));
# }
Run the code above in your browser using DataLab