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:

  1. size :- total program size (611450 X 4096/1024 = 2445800kB = 2388M)
  2. resident :- resident set size (185001 X 4096/1024 = 740004kB = 722M)
  3. share :- shared pages (883 X 4096 = 3532)
  4. trs :- text (code) (18 X 4096/1024 = 72kB = VmExe )
  5. drs :- data/stack
  6. lrs :- library (593431 X 4096/1024 = 2373724kB = VmData +VmStk)
  7. dt :- dirty pages

Also you can log the memory activity for your process doing a loop using date and cat.