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?


Method 1



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 :
    ps faux | grep casper
    sleep 1s
  • 1
    How can you change it from showing %? Out of interest :-)
    – Wilf
    Dec 17 '13 at 20:58
  • I get this when running the script: bash: ./memory_usage.sh: bin/bash: bad interpreter: No such file or directory Dec 17 '13 at 21:12
  • Bah! I have edited it! Should have checked it properly before posting. The first line should say where to run it from /bin/bash (I had bin/bash so it was checking locally in a folder called bin for bash) Dec 17 '13 at 21:31
  • 1
    @ wilf ps faux | grep casper | awk '{print $11} {print $6}' That should give you on one line the program name and the next the real memory size in kB. Dec 17 '13 at 21:34

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


  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.


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
  • 1
    With pmap -x PID, did you mean incredibly detailed usage :-)
    – Wilf
    Dec 17 '13 at 20:59
  • indeed - can never have enough detail :) Dec 17 '13 at 21:05
  • 1
    On mine (Ubuntu 16.04.5 LTS) "pmap -x" with the PID doesn't show anything other than the PID and the command. -X does the same.
    – orrd
    Sep 24 '19 at 22:00

Open 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.

  • 2
    You don't need the -v grep if you change the final one to grep [c]asper. That matches casper but not itself.
    – Wudang
    Jul 16 '19 at 9:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.