2019-07-05 21:45:30 +03:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
echo "Running executable"
|
|
|
|
|
|
|
|
PID=0
|
|
|
|
EXITCODE=0
|
|
|
|
|
|
|
|
# launch process in background
|
|
|
|
eval $* &
|
|
|
|
# capture process ID to monitor
|
|
|
|
PID=$!
|
|
|
|
|
|
|
|
# Timeout duration
|
2021-04-14 18:54:49 +03:00
|
|
|
TIME=800
|
2019-07-05 21:45:30 +03:00
|
|
|
|
|
|
|
while (($TIME > 0)); do
|
|
|
|
# polling interval
|
|
|
|
sleep 5
|
|
|
|
|
|
|
|
# check if process is still running
|
|
|
|
ps ax | grep $PID | grep -v grep > /dev/null
|
|
|
|
if test "$?" != "0"
|
|
|
|
then
|
|
|
|
# process exited so lets get the exit code
|
|
|
|
wait $PID
|
|
|
|
EXITCODE=$?
|
|
|
|
echo "Finished running with exit code: "$EXITCODE
|
|
|
|
exit $EXITCODE
|
|
|
|
fi
|
|
|
|
((TIME -= 5))
|
|
|
|
done
|
|
|
|
|
|
|
|
# process taking too long, kill it
|
|
|
|
kill -9 $PID
|
|
|
|
|
|
|
|
echo "Process took too long"
|
2021-04-14 18:54:49 +03:00
|
|
|
exit 1
|