use either &&
or ;
:
%x(ulimit -St #{max_time} && heavy_program)
%x(ulimit -St #{max_time}; heavy_program)
However using ulimit
may be not what you really need, consider this code:
require 'timeout'
Timeout(max_time){ %x'heavy_program' }
ulimit
limits CPU time, and timeout
limits total running time, as we, humans, usually count it.
so, for example, if you run sleep 999999
shell command with ulimit -St 5
- it will run not for 5 seconds, but for all 999999 because sleep
uses negligible amount of CPU time