The following script should kill all the queries taking more than say 600 seconds. But it seems that it is killing queries taking more than 6 seconds.
>> sh myscript.sh 600
#!/bin/bash
#kill runaway processes
SEC=$1
ifs='|'
if [[ $SEC -lt 1 ]]; then
echo "Usage: $0 seconds"
exit 1
fi
mysqladmin processlist -v | grep Query | grep -Evi "delete|update|insert|alter table" | while read dummy qid qusr qhost qdb qstat qsec qstat2 query
do
if [[ $qsec > $SEC ]]; then
echo "Killing query $qid..."
mysqladmin kill $qid
fi
done