How to monitor the memory consumed by a process?

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
4

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.

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
3

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.

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like