Jump to content

bpmircea

Members
  • Posts

    11
  • Joined

  • Last visited

Posts posted by bpmircea

  1. Gasire proces ce papa mult RAM dupa nume, terminare + log:

    Se inlocuie !!NAME!! cu ce aveti nevoie.

    Este folositor cand stiti ca un anumit proces mananca mult, si vreti sa il inchideti automat.

    Se face CRON pe fisier si se rezolva.

    Sper ca ajuta pe cineva, mie mi-a fost de folos.


    #! /bin/bash
    # Author : zekStein++ ( Adrian Constantin # b3kwz@yahoo.com )

    iMaxUsage=512000 #This is the maximum memory usage permited !

    #Here we took all the pids of the running processes

    iPids=$( ps -U root -u root -N | grep !!NAME!! | grep -o -P "(.*)(?=pts)");

    #Here we parse the PIDS and search for HIGH MEMORY USAGE !

    for i in $iPids
    do

    #Here we check all the usages for that PIDS !

    iMemoryUsage=$( pmap $i | awk -F"total" '{print $2}' | grep K | tr -d " " | tr -d "K" );

    #Here we will compare with the maximum MEMORY USAGE PERMITED!
    #Also, we kill the process and log it to know at any time who was the joker .

    if [ $iMemoryUsage -gt $iMaxUsage ]
    then

    sPidOwner=$(ps -ef | grep $i | grep -o -P '(.*)(?=$i)' | cut -d"r" -f1 | grep " "); # Unstable.
    sDateAndTime=$(date)
    kill $i
    echo "Data si ora : $sDateAndTime , utilizator : $sPidOwner ;" >> /home/InformatiiConsumRam.log

    fi

    done

    #Script job done !

    eu il caut cu top si dupa aia omor procesul cu kill, ceva in genul asta:

    top | grep nume_program

    kill PID_de_program

×
×
  • Create New...