Mercurial > hg > aboriginal
view more/timeout.sh @ 1252:ba951c11fb48
Refactor the gentoo bootstrap build some more. Add "build" and "files" subdirectories, split each package build into a separate file, break out reusable shell functions into functions.sh. Flow control now init chrooting into run-build-stages.sh calling the individual package scripts.
author | Rob Landley <rob@landley.net> |
---|---|
date | Sat, 25 Sep 2010 13:40:04 -0500 |
parents | 300e6d919d86 |
children | 2868f2d87624 |
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 "Usage: timeout.sh SECONDS COMMANDS..." >&2 exit 1 fi trap "killtree $$" EXIT TIMEOUT="$1" shift ( eval "$@" ) | tee >(while read -t "$TIMEOUT" -n 32 i; do true; done; sleep 1; kill -TERM $$ 2>/dev/null )