For testing purposes, I want to know if there is a flag I can pass to java
in order to limit the total execution time and memory usage of a .class
file.
Motivation: let's say that I automatically download someone else's code and I run it automatically, but I don't know if the code is (unintentionally) buggy and will crash my automated system if it is caught in an infinite loop or is increasingly using memory to the limit of the system.
I read here that using the flag -Xmx
you can limit the memory usage, but I can't seem to find the way to limit running time. Reading the documentation it seems like there is a way of limiting the CPU usage during execution, but that is not what I want, I want the program ended (killed if necessary) if it has been running for more than, say, 5min.
Example of what I want:
java -Xmx1m -time5m a_java_program
for limiting memory usage to 1Mb and time to 5min.
Is there something like this for java?