#!/bin/bash
function get_line_count()
{
awk 'END{print NR}' todisc.log
}
check_stall()
{
newlines=$(get_line_count)
while ps -p $TCODE_PID >/dev/null; do
# Check for transcode output every 5 seconds
sleep 5
lines=$newlines
newlines=$(get_line_count)
# If no new output, sleep 30s and check again
((newlines == lines)) && sleep 30 && newlines=$(get_line_count)
# If still no new lines, kill transcode
if ((newlines == lines)); then
echo "transcode appears to be stalled"
echo "We are going to send transcode a HUP and hope for the best"
sleep 5
$(kill -0 $TCODE_PID > /dev/null 2>&1) && kill -HUP $TCODE_PID
fi
done
}