The problem:
Given a process, limit the resources it and its child-processes can use. I.e. set CPU time and virtual memory quotas. When the process group exceeds one of the limits, terminate it, otherwise print the amount of CPU time and virtual memory it has used.
The concrete use case:
Basically I must execute a couple of binaries, which expect input from a file, but I must ensure that their execution process is strictly limited. For example the binary must not allocate more than 256 MB of memory and it should run for less than 0.5 seconds. However I need information about the amount of memory and CPU it has used.
What I have tried:
- For a couple of days I have been dealing with this perl script, which is the best solution I have found so far. Unfortunately its memory is buggy and it is not very precise. Also there is an official author post about this script here.
- I have tried using both
/usr/bin/timeout
andtimeout
Linux tools, which of course help me with the CPU time quota, but not with the termination of the process due to violation of the virtual memory limit. - Using
ulimit
was attempted as well but as I have said earlier I need not only limitation but feedback for the resource consumption too.
The Question:
What can solve this issue? .
setrlimit
can limit CPU time only for an integral number of seconds)setrlimit