Changes in directory llvm-test:
TimedExec.sh added (r1.1) RunSafely.sh updated: 1.19 -> 1.20 --- Log message: Fork a watch dog process that sleeps for a specified period of time and then wakes up and kill the parent process. This works for targets where ulimit -t is not reliable. --- Diffs of the changes: (+45 -1) RunSafely.sh | 8 +++++++- TimedExec.sh | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) Index: llvm-test/TimedExec.sh diff -c /dev/null llvm-test/TimedExec.sh:1.1 *** /dev/null Wed Jun 7 13:57:46 2006 --- llvm-test/TimedExec.sh Wed Jun 7 13:57:36 2006 *************** *** 0 **** --- 1,38 ---- + #!/bin/sh + # + # Program: TimedExec.sh + # + # Synopsis: This script is a watchdog wrapper. It runs the specified program + # but times out if it does not complete in the allocated time frame. + # Syntax: ./TimedExec.sh <timeout> <program> <args...> + # + + if [ $# -lt 2 ]; then + echo "./TimedExec.sh <timeout> <program> <args...>" + exit 1 + fi + + PARENT="" + if [ "$1" == "-p" ]; then + PARENT=$2; shift; shift; + fi + + TIMEOUT=$1 + PROGRAM=$2 + shift + + if [ -z "$PARENT" ]; then + # Start a watchdog process + $0 -p $$ $TIMEOUT $PROGRAM $* & + WATCHDOG="$!" + exec "$@" + # I am done first. kill the watch dog. + kill $WATCHDOG && (sleep 2; kill -1 $WATCHDOG) && (sleep 2; kill -9 $WATCHDOG) + else + # Sleep for a specified time then wake up to kill the parent process. + exec > /dev/null 2>&1 + sleep $TIMEOUT + kill $PARENT && (sleep 2; kill -1 $PARENT) && (sleep 2; kill -9 $PARENT) + fi + + exit 0 Index: llvm-test/RunSafely.sh diff -u llvm-test/RunSafely.sh:1.19 llvm-test/RunSafely.sh:1.20 --- llvm-test/RunSafely.sh:1.19 Tue Aug 2 17:04:00 2005 +++ llvm-test/RunSafely.sh Wed Jun 7 13:57:36 2006 @@ -13,6 +13,12 @@ # # Syntax: ./RunSafely.sh <ulimit> <stdinfile> <stdoutfile> <program> <args...> # +if [ $# -lt 4 ]; then + echo "./RunSafely.sh <timeout> <stdinfile> <stdoutfile> <program> <args...>" + exit 1 +fi + +DIR=${0%%`basename $0`} ULIMIT=$1 INFILE=$2 OUTFILE=$3 @@ -51,7 +57,7 @@ # we tell time to launch a shell which in turn executes $PROGRAM with the # necessary I/O redirection. # -( time -p sh -c "$PROGRAM $* > $OUTFILE 2>&1 < $INFILE" ) 2>&1 | awk -- '\ +( time -p sh -c "${DIR}TimedExec.sh $ULIMIT $PROGRAM $* > $OUTFILE 2>&1 < $INFILE" ) 2>&1 | awk -- '\ BEGIN { cpu = 0.0; } /^user/ { cpu += $2; print } /^sys/ { cpu += $2; print } _______________________________________________ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits