DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Kill Runaway Processes

10.22.2011
| 2573 views |
  • submit to reddit
        // kill runaway select processes taking more than 900 seconds

#!/bin/bash
#kill runaway select processes taking more than 900 seconds
IFS='|'
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 -gt 900 ]]; then
echo "Killing query $qid..."
mysqladmin kill $qid
fi
done