Time limited scons team

I want to limit the execution time of the program that I run on Linux. I put a line like in my scons script:

Command ("com", "," ulimit -t 1; myprogram ")

and tested it with a program with an infinite loop: it did not work, and the program was executed forever.

Did I miss something?

- tsf

+3
source share
2 answers

ulimit -t 1 , 1 . sleep , . , 1 . 1 .

, SCons? , ...

ulimit -t 1; ./myprogram

, , 0:

bash: ulimit: cpu time: cannot modify limit: Operation not permitted

: , -t Ubuntu 9.04. 05 2009 , , - 9.10.

Ubuntu 10.04.

+4

script:

( http://newsgroups.derkeiler.com/Archive/Comp/comp.sys.mac.system/2005-12/msg00247.html)

#!/bin/sh
# timeout script
#
usage()
{
echo "usage: timeout seconds command args ..."
exit 1
}

[[ $# -lt 2 ]] && usage
seconds=$1; shift

timeout()
{
sleep $seconds
kill -9 $pid >/dev/null 2>/dev/null
}

eval "$@" &
pid=$!
timeout &
wait $pid
.
0

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


All Articles