toolbelt/timeout
2014-01-23 14:07:15 +01:00

22 lines
303 B
Bash
Executable file

#!/bin/sh
# $0 [OPTION] DURATION COMMAND [ARG]...
# DURATION with suffix: s, m, h, d
# -k --kill--after
# -s --signal
# exit: 124
set -e
set -o nounset
wrapper_pid=$$
seconds="$1"
shift
signal='TERM'
(sleep $seconds; kill $wrapper_pid) &
watchdog_pid=$!
trap "kill -$signal $watchdog_pid" EXIT
$@