comparison more/timeout.sh @ 1157:300e6d919d86

Move "sources/more/" to just "more/", add a README explaining why those scripts are there, and adjust calls to them.
author Rob Landley <rob@landley.net>
date Mon, 05 Jul 2010 15:37:04 -0500
parents sources/more/timeout.sh@716ad74e0598
children 2868f2d87624
comparison
equal deleted inserted replaced
1156:8ab750338f73 1157:300e6d919d86
1 #!/bin/bash
2
3 # Run a command line with a hang timeout, which kills the child process if it
4 # doesn't produce a new line of output for $1 seconds.
5
6 # This script has to be a separate process (rather than just a shell function)
7 # so killing it doesn't kill the parent process.
8
9 source sources/functions.sh
10
11 if [ $# -lt 1 ]
12 then
13 echo "Usage: timeout.sh SECONDS COMMANDS..." >&2
14 exit 1
15 fi
16
17 trap "killtree $$" EXIT
18 TIMEOUT="$1"
19 shift
20 ( eval "$@" ) | tee >(while read -t "$TIMEOUT" -n 32 i; do true; done; sleep 1; kill -TERM $$ 2>/dev/null )