[clug] time's memory options don't work

David Tulloh david at tulloh.id.au
Wed Jun 17 02:05:26 GMT 2009


Chris Smart wrote:
> Hey all,
>
> I'm trying to work out how much memory a process is using from start
> to finish. Do to that I'm using GNU time (not bash) /usr/bin/time
> which can apparently tell me with %K:
> "Average total memory use of the process in Kbytes."
>
> I.e.
> /usr/bin/time -f %K [command]
>
> Problem is that it just doesn't work. I always get a value of zero. In
> fact all memory related options always present zero as the result.
>
> Does anyone know why or how to fix it?
>   
I've never used time for this, but you can get a snapshot of a processes 
memory use from /proc/process_id/statm

Redhat says the seven columns are:

   1.

      Total program size, in kilobytes.

   2.

      Size of memory portions, in kilobytes.

   3.

      Number of pages that are shared.

   4.

      Number of pages that are code.

   5.

      Number of pages of data/stack.

   6.

      Number of library pages.

   7.

      Number of dirty pages.


Tie this in with watch and you can track the usage through time.
watch -n 1 'bash -c "cat /proc/13860/statm | tee -a ~/13860.mem"'

I'm not sure if this will track the startup usage because you need to 
start it after you get the id, and you need to post-process it to get 
the precise information you are after....  but it's one way of looking 
at the problem.


David


More information about the linux mailing list