#!/bin/bash # Run a command line with a hang timeout, which kills the child process if it # doesn't produce a new line of output for $1 seconds. # This script has to be a separate process (rather than just a shell function) # so killing it doesn't kill the parent process. source sources/utility_functions.sh if test $Argc -lt 1 { echo "Usage: timeout.sh SECONDS COMMANDS..." > !2 exit 1 } trap "killtree $Pid" EXIT global TIMEOUT := $1 shift shell { eval @Argv } | tee $[while read -t "$TIMEOUT" -n 32 i { true; }; sleep 1; kill -TERM $Pid !2 >/dev/null]