Mercurial > hg > aboriginal
view sources/timeout.sh @ 980:d424fd68f991
Idea from Johnicholas Hines: add a three second "read" before running hdc's init so the user can press a key to get a command shell instead.
author | Rob Landley <rob@landley.net> |
---|---|
date | Tue, 16 Feb 2010 08:26:35 -0600 |
parents | 2ca7ea5d3ec1 |
children |
line wrap: on
line source
#!/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/functions.sh if [ $# -lt 1 ] then echo "Need timeout value" >&2 exit 1 fi trap "killtree $$" EXIT TIMEOUT="$1" shift ( "$@" ) | tee >(while read -t "$TIMEOUT" -n 32 i; do true; done; sleep 1; kill -TERM $$ 2>/dev/null )