I have a process that I would like to see how much memory it consumes while it is running.
Right now I do this:
ps faux | grep casper But that just gives me the information of that moment. It would be nice to see that value changing as the script proceeds.
Any way I can do this?
5 Answers
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 4To 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.
you could use use top
man top This program allows you to sort the resource usage by, amongst others, RSS, VSZ, CPU, etc... It's very useful.
Alternatively, for a more detailed breakdown of memory usage, try 'pmap'
man pmap Example usage:
pmap -x 1234 3Open System Monitor, and go to the Processes tab:
![]()
Give this a try:
watch 'ps faux | grep -v grep | grep casper' You may also change refresh interval using the --interval <seconds> parameter.