#! /bin/sh

# problem: conftest programs getting stuck
# solution: run this until it can be fixed.

# pidlist(): list stuck conftest processes
#
# converts:
#       TIME   PID UCOMM
#    0:00.02 96074 conftest
# to:
#    00002 96074 conftest
#
# and filters out < 10m processes. 
#

pidlist() {
        ps -o time -o pid -o comm \
                | sed -e 's/0:/0/' -e 's:\.::g' -e 's:^ *::' \
                | egrep -v '^(TIME|00)' |grep conftest \
                | cut -wf 2
}

while true; do

        stuck="`pidlist`";
        if [ ! -z "$stuck" ]; then
                echo `date` : stuck proceses detected: $stuck;
                for p in $stuck; do
                        ps axw |grep "^$p";
                        # list job - FIXME won't work for -J bulks..
                        ls -lrt /pkgsrckit/bulklog |tail -n 1;
                        kill -9 $p;
                        echo;
                done
        fi
        sleep 5;
done


