Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- if [ $(id -u) -ne 0 ]; then
- echo "must be run as root"
- exit 1
- fi
- for U in $(ps -e -o user | tail -n +2 | sort | uniq); do
- TOTAL_RSS=0
- PS_COUNT=0
- while read CPID CRSS; do
- PS_COUNT=$(expr ${PS_COUNT} + 1)
- TOTAL_RSS=$(expr ${TOTAL_RSS} + ${CRSS})
- MAX_RSS=${CRSS}
- MAX_RSS_PID=${CPID}
- done < <(ps -u ${U} -o pid,rss | tail -n +2 | sort -n -k 2)
- if [ ${PS_COUNT} -gt 0 ]; then
- AVGRSS=$(expr ${TOTAL_RSS} / ${PS_COUNT})
- echo "${U} ${PS_COUNT} ${TOTAL_RSS}"
- if [ ${MAX_RSS} -gt $(expr ${AVGRSS} "*" 2) ]; then
- echo -e "\tpid ${MAX_RSS_PID} has ${MAX_RSS}, will terminate"
- kill -s SIGTERM ${MAX_RSS_PID}
- sleep 2
- kill -s SIGKILL ${MAX_RSS_PID}
- fi
- fi
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement