Is there a way to limit the time and memory resources for running the bash command?

Basically, I want to run compiled C ++ code and limit the execution time (for example, to the second) and memory (up to 100 thousand), like online judges. Can I add parameters to the command? This must be done without changing the source code.

+4
source share
2 answers

Try to run the command ulimit, it can set limits on the time and memory of the processor.

Try this example.

bash -c 'ulimit -St 1 ; while true; do true; done;'

The result you get will be

CPU time limit exceeded (core dumped)
+6
source

To limit time, you can use the "timeout" command

timeout 15s command

Check it out for more details: link

+2

Source: https://habr.com/ru/post/1624426/


All Articles