How to monitor the memory consumed by a process?
Solution 1:
Method 1
Run:
top
Check for the program's PID (first column), then run:
top -p PID
Method 2
Either paste this into the terminal or save it as a mem_usage.sh and run it from terminal.
#! /bin/bash
while :
do
clear
ps faux | grep casper
sleep 1s
done
Solution 2:
To monitor only your process you can check /proc/PID/status or /proc/PID/statm
.
About /proc/PID/statm
:
After doing cat /proc/PID/statm
you should see this:
611450 185001 883 18 0 593431 0
Explanation:
- size :- total program size (611450 X 4096/1024 = 2445800kB = 2388M)
- resident :- resident set size (185001 X 4096/1024 = 740004kB = 722M)
- share :- shared pages (883 X 4096 = 3532)
- trs :- text (code) (18 X 4096/1024 = 72kB = VmExe )
- drs :- data/stack
- lrs :- library (593431 X 4096/1024 = 2373724kB = VmData +VmStk)
- dt :- dirty pages
Also you can log the memory activity for your process doing a loop using date
and cat
.