I use a tool to create PDF files, which, unfortunately, is not 100% reliable. Sometimes this tool gets into an infinite loop and consumes 100% of memory and processor.
I run this tool from my Java application using Runtime.getRuntime.exec("command") .
- Is there a way to set the maximum runtime / memory for this process directly in the Java command?
- If not directly from Java, is there a way to wrap the command in some bash tool that will limit resources?
I prefer the team to fail than use all the resources and basically kill the server.
EDIT
Based on ulimit suggestions, I try this:
Runtime.getRuntime() .exec(arrayOf("bash", "-c", "ulimit -m 2; ulimit -a; pdfprint"))
I see ulimit working:
core file size (blocks, -c) 0 data seg size (kbytes, -d) unlimited file size (blocks, -f) unlimited max locked memory (kbytes, -l) unlimited max memory size (kbytes, -m) 2 open files (-n) 10240 pipe size (512 bytes, -p) 1 stack size (kbytes, -s) 8192 cpu time (seconds, -t) unlimited max user processes (-u) 709 virtual memory (kbytes, -v) 2
The strange thing is that I expected pdfprint to crash because it would pdfprint out of memory. However, this does not happen, and the program works correctly.
source share