KILL Firefox HIGH MEM

De Wiki Hackstore

Monitor de consumo de memória ram pelo Firefox

Com esse script é possível eliminar o processo do firefox caso o mesmo consuma demasiada memória ram.

mkdir -p /opt/hackstore ; vi /opt/hackstore/kill-firefox
#!/bin/bash

## Adicione ao crontab:
## * * * * *     root    /opt/hackstore/kill-firefox

## Variáveis ##
INTERVALO_SEGUNDOS="10"
MAX_RAM="40"

DAEMON_NAME="kill-firefox"
LOCK="/tmp/${DAEMON_NAME}.lock"
LOG="/var/log/kill-firefox.log"
BIN="/usr/lib64/firefox/firefox"


## Funções ##
{
if ! flock -n 777; then
        COMMAND_CHECK="$(ps auxw|grep -w "${BIN}"|grep -vw 'grep')"
        PID="$(echo "${COMMAND_CHECK}"|awk '{print $2}')"
        CPU="$(echo "${COMMAND_CHECK}"|awk '{print $3}')"
        MEM="$(echo "${COMMAND_CHECK}"|awk '{print $4}')"
        echo -e "\nPID: ${PID} (${BIN})"
        echo "Uso de cpu: ${CPU}%"
        echo "Uso de ram: ${MEM}%"
        echo -e "Uso maximo de ram: ${MAX_RAM}%\n"
        exit 1
else
        while [ 1 ]; do
                COMMAND_CHECK="$(ps auxw|grep -w "${BIN}"|grep -vw 'grep')"
                PID="$(echo "${COMMAND_CHECK}"|awk '{print $2}')"
                CPU="$(echo "${COMMAND_CHECK}"|awk '{print $3}')"
                MEM="$(echo "${COMMAND_CHECK}"|awk '{print $4}')"
                MEMCHECK="$(echo "${COMMAND_CHECK}"|awk '{print $4}'| cut -d '.' -f1)"
                echo "Uso de ram: ${MEMCHECK}%"
                        if [ "${MEMCHECK}" -gt "${MAX_RAM}" ]; then
                                kill -9 ${PID}
                                echo -e "\nFirefox reiniciado.....\n${COMMAND_CHECK}" >> ${LOG}
                        fi
                        # Intervalo
                        sleep ${INTERVALO_SEGUNDOS}
        done
fi

} 777>${LOCK};rm ${LOCK}