mirror of
https://github.com/lloeki/toolbelt.git
synced 2025-12-06 01:54:41 +01:00
timeout utility
This commit is contained in:
parent
a8d8b99f0f
commit
72e401c0dd
1 changed files with 22 additions and 0 deletions
22
timeout
Executable file
22
timeout
Executable file
|
|
@ -0,0 +1,22 @@
|
|||
#!/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
|
||||
|
||||
$@
|
||||
Loading…
Add table
Add a link
Reference in a new issue