I searched a lot on the internet but somehow nothing works. I got an application called myApp
and I want to display the memory usage of this app at discrete points of time. I need sth. like this:
#!/bin/bash
for((i=0;i<=20;++i))
do
... check memory usage here
sleep 3
done
I cannot use pidof
since the command is not found. Till now, I got this:
#!/bin/bash
PROCESSNAME=myApp
MYPID=`pgrep -f $PROCESSNAME`
echo "=======";
echo PID:$MYPID
echo "--------"
Rss=`echo 0 $(cat /proc/$MYPID/smaps | grep Rss | awk '{print $2}' | sed 's#^#+#') | bc;`
Shared=`echo 0 $(cat /proc/$MYPID/smaps | grep Shared | awk '{print $2}' | sed 's#^#+#') | bc;`
Private=`echo 0 $(cat /proc/$MYPID/smaps | grep Private | awk '{print $2}' | sed 's#^#+#') | bc;`
Swap=`echo 0 $(cat /proc/$MYPID/smaps | grep Swap | awk '{print $2}' | sed 's#^#+#') | bc;`
Pss=`echo 0 $(cat /proc/$MYPID/smaps | grep Pss | awk '{print $2}' | sed 's#^#+#') | bc;`
Mem=`echo "$Rss + $Shared + $Private + $Swap + $Pss"|bc -l`
echo "Rss " $Rss
echo "Shared " $Shared
echo "Private " $Private
echo "Swap " $Swap
echo "Pss " $Pss
echo "=================";
echo "Mem " $Mem
echo "=================";
I call this myApp
from NetBeans (it's a C++ program). Unfortunately, pgrep -f myApp
returns two PIDs so nothing works in my script. Actually, I have nearly no knowledge about bash-scripts and thus, no idea what to do now.
Another question: Looking at "System Monitor" of Linux the "Memory"-column gives me other values than this script here. Can you tell me why? Which of the Types (Rss, Shared,...) equals this "Memory"-column of "System Monitor"?