How can I monitor memory usage of a process running from the terminal in OSX

8

I am running a command line utility called casperJS (installed via node npm) from the OSX terminal. It's a long running process and I'd like to see how much memory it is using, together with any subprocesses.

I don't see the process in Activity Monitor so how I can tell how much memory it is using?

codecowboy

Posted 2014-01-11T09:22:14.727

Reputation: 465

Look for phantomjs or slimerjs. – Daniel Beck – 2014-01-11T09:46:38.957

Answers

5

In Activity Monitor, you can view the list of processes hierarchically, to easily find any processes started from Terminal. Just select All Processes, Hierarchically in the toolbar.

Screenshot

For the tool in question, I'd expect the processes to be called phantomjs or slimerjs based on the Python launcher.

Daniel Beck

Posted 2014-01-11T09:22:14.727

Reputation: 98 421

9

You can use ps for that, for example:

ps x -o rss,vsz,command | grep FooProcess

then sort by the real memory (resident set) size of the process using (sort -nr).

kenorb

Posted 2014-01-11T09:22:14.727

Reputation: 16 795

6

you can use this command for monitoring usage of PROCESSNAME

top -l 1|grep "PROCESSNAME"|awk '{print "MEM="$9 "\tRPRVT="$10}'

abzcoding

Posted 2014-01-11T09:22:14.727

Reputation: 231

Version with the name in the front: top -l 1 | grep "FOO" | awk '{print "NAME="$2 " MEM="$9 "\tRPRVT="$10}'. – kenorb – 2015-08-25T10:22:38.513

He doesn't seem to know the process name. Otherwise it'd show up in Activity Monitor. – Daniel Beck – 2014-01-11T09:45:26.923

sorry i did not expect that one! – abzcoding – 2014-01-11T09:46:18.867

0

You can run the same program, but forwarding x11.

This means you'll get the physical window open up on your desktop from which you're SSHing in from - It's much nicer in terms of visualisation

Here's a tutorial on how to set up x11. It's really simple to do, and it's much nicer. (plus it's useful for running graphical installer wizards too!)

http://dyhr.com/2009/09/05/how-to-enable-x11-forwarding-with-ssh-on-mac-os-x-leopard/

EDIT: Here's an example I've screenshotted for you of me SSHing in with X11 forwarding(putty) from my Windows machine to my Linux machine, then starting up my system monitor Ksysguard. As you can see the whole window appears as it would do if you were on the actual machine. Capture of SSH and X11

Image of process manager running via x11

Jay

Posted 2014-01-11T09:22:14.727

Reputation: 660

can you please mention in your answer if this also works on OSX since the OP asked about OSX specifically? – Thatkookooguy – 2016-05-18T08:07:48.710

Yes it does work! – Jay – 2016-07-05T14:45:34.197

I asked that you'll add it in your answer since the original poster asked about OS X specifically. – Thatkookooguy – 2016-07-05T15:12:55.027