1

I was wondering if there was a way to use top or another program to track the memory consumption of a script I will be running. I was using

   runtime.totalMemory - runtime.freeMemory

But that's not cutting it, as it takes into consideration the whole system, not just the process I want to track.

I'm using a shell script to run a scala program which I want to have its memory usage tracked.

1
  • On something with a /proc filesystem and the pid of the child process, you could dig around thereunder for the per-process memory details.
    – thrig
    Jun 16, 2016 at 17:45

2 Answers 2

1

Get the PID of the scala process you want to track using SCALAPID=$! after starting the scala process in background then find the memory usage of the process using ps -o size= -q $SCALAPID the returned value is in kilobytes

0

If you want to check memory of a process which is already running then try this:

# ./ps_mem.py
 Private  +   Shared  =  RAM used       Program

188.0 KiB +  52.0 KiB = 240.0 KiB       atd
.....
 25.9 MiB +  66.0 KiB =  26.0 MiB       memcached
 53.1 MiB + 106.5 KiB =  53.2 MiB       named
453.2 MiB + 107.0 KiB = 453.3 MiB       mysqld
---------------------------------
                          1.2 GiB
=================================

If you're asking about script you're going to run then I believe there's no way to check it because it may call whatsoever which it its turn can call a lot of stuff too etc.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .