forked from isislovecruft/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexecutioner
More file actions
executable file
·34 lines (30 loc) · 783 Bytes
/
executioner
File metadata and controls
executable file
·34 lines (30 loc) · 783 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/bin/bash
##############################################################################
# executioner
# -----------
# Run process $2 for $1 seconds and then kill the process.
#
# :authors: Isis Agora Lovecruft, 0xa3adb67a2cdb8b35
# :date: 21 April 2013
# :version: 0.0.2
##############################################################################
set -vx --
function killitwithfire () {
trap - ALRM
kill -ALRM $prog 2>/dev/null
kill -9 $! 2>/dev/null && exit 0
}
function waitforit () {
trap "killitwithfire" ALRM
sleep $1& wait
kill -ALRM $$
}
waitforit $1& prog=$! ; shift ;
trap "killitwithfire" ALRM INT
"$@"& wait $!
RET=$?
if [[ "$(ps -ef | awk -v pid=$prog '$2==pid{print}{}')" != "" ]]; then
kill -ALRM $prog
wait $prog
fi
exit $RET