Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find the memory consumption of a particular process in linux for every 5 seconds

I just want to know how to find the memory consumption of a particular process for particular time(say 5 seconds)

I am new to linux. So, detailed steps of doing that will be appreciated

like image 774
Vamsi Avatar asked Feb 01 '13 07:02

Vamsi


1 Answers

you may use SNMP to get the memory and cpu usage of a process in a particular device in network :)

Requirements:

  • the device running the process should have snmp installed and running
  • snmp should be configured to accept requests from where you will run the script below(it may be configured in snmpd.conf)
  • you should know the process id(pid) of the process you want to monitor

Notes:

  • HOST-RESOURCES-MIB::hrSWRunPerfCPU is the number of centi-seconds of the total system's CPU resources consumed by this process. Note that on a multi-processor system, this value may increment by more than one centi-second in one centi-second of real (wall clock) time.

  • HOST-RESOURCES-MIB::hrSWRunPerfMem is the total amount of real system memory allocated to this process.

**

Process monitoring script:

**

echo "IP: "
read ip
echo "specfiy pid: "
read pid
echo "interval in seconds:"
read interval

while [ 1 ]
do
    date
    snmpget -v2c -c public $ip HOST-RESOURCES-MIB::hrSWRunPerfCPU.$pid
    snmpget -v2c -c public $ip HOST-RESOURCES-MIB::hrSWRunPerfMem.$pid
    sleep $interval;
done
like image 174
Roselyn Verbo Domingo Avatar answered Oct 01 '22 23:10

Roselyn Verbo Domingo