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
.
Solution 3
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
Solution 4
Open System Monitor, and go to the Processes tab:
Solution 5
Give this a try:
watch 'ps faux | grep -v grep | grep casper'
You may also change refresh interval using the --interval <seconds>
parameter.
Related videos on Youtube
John Boe
Updated on September 18, 2022Comments
-
John Boe over 1 year
How to check if property cssRules exists in document.styleSheets[i] object?
I have found out that I cannot use
if ( sheets[i].hasOwnProperty("cssRules") ) because .cssRules is inherited property.
But when I try to use
if( sheets[i].cssRules !== undefined )
so in debugger (Firefox 48 Toolbox tool) I got exception: SecurityError.
For this reason the code fails.
var cssList = function(node) { var sheets = document.styleSheets, o = {}; var sheet; for (var i in sheets) { if( sheets[i].cssRules !== undefined ) sheet = sheets[i].cssRules; else if( sheets[i].rules !== undefined ) sheet = sheets[i].rules; else continue; var rules = sheets[i].rules || sheets[i].cssRules; } return o; }
-
CBroe over 7 yearsIf you’re getting a security error, then that is probably a cross-domain issue – is the stylesheet in question being loaded from a different domain?
-
John Boe over 7 yearsNot the stylesheet. The script is injected from Firefox webextensions (addon). So the web-page is remote and script is on client side. But the webextensions works like that it pretends to be part of the page. Maybe it is some security policy of the Firefox addons.
-
-
Wilf over 10 yearsHow can you change it from showing %? Out of interest :-)
-
Wilf over 10 yearsWith
pmap -x PID
, did you mean incredibly detailed usage :-) -
swisscheese over 10 yearsindeed - can never have enough detail :)
-
Hommer Smith over 10 yearsI get this when running the script: bash: ./memory_usage.sh: bin/bash: bad interpreter: No such file or directory
-
Julian Stirling over 10 yearsBah! 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)
-
Julian Stirling over 10 years@ 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.
-
John Boe over 7 yearsThe code is in Firefox webextensions. It is Content Script injected into web-page (a blog). "cssRules" in sheet also was not working.
-
the8472 over 7 yearsthen it's probably a cross-domain
<link>
? -
John Boe over 7 yearsHey, you are genius. Thanks a lot! The catch ... try works!
-
Wudang almost 5 yearsYou don't need the -v grep if you change the final one to grep [c]asper. That matches casper but not itself.
-
orrd over 4 yearsOn 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.