1

I just wondered if I have already the max RSS value given by time -v, is there any way to get the right RSS value from this command line or as it is wrong, there is no way to find out the right value in KB or another unit? Any other unix command that could determine the memory usage of a process (program) from the beginning of the process to the end as average or max?

Look forward to your reply,

Carol

carol
  • 153
  • 1
  • 4
  • 17

1 Answers1

0

On Linux, you could consider using proc(5). So for process of pid 1234, try cat /proc/1234/maps in a terminal (try also cat /proc/$$/maps for the current shell, etc...). It shows the current address space in virtual memory.

From inside the process, read sequentially the /proc/self/maps pseudo-file.

See also /proc/self/stat, /proc/self/statm, /proc/self/status (which you could parse and get the VmRSS: line).

You could also use time(1) & top(1): both commands can be used/configured to show RSS. And also watch(1) with ps(1) (e.g. watch ps -l 1234)

Read also about process accounting, e.g. acct(5) etc...

You could run your program with time -v yourprogram its arguments....

See also getrusage(2) & wait4(2)

Read also linuxatemyram

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547
  • but if I have a program that takes 2h to run, how can I determine the max or average RAM that it has used without being in front of a terminal when it's running? – carol Jan 21 '15 at 13:14
  • Nitpicking: what is running is a *process* – Basile Starynkevitch Jan 21 '15 at 13:16
  • Once the process has terminated you usually cannot know how much resources it has used. – Basile Starynkevitch Jan 21 '15 at 13:17
  • the problem is that the max RSS given by time -v is wrong (see another thread about this in stakoverflow). The problem comes from gnu. otherwise, time -v is perfect as I need such a command to precede my program command line so that the max RAM could be determined during the run time. – carol Jan 21 '15 at 13:28
  • it's much much more that what is used. I try to follow the memory usage with system monitor and compared to what was determined by time and it was totally crapped. see also http://stackoverflow.com/questions/774556/peak-memory-usage-of-a-linux-unix-process – carol Jan 21 '15 at 13:35
  • Then sample `/proc/1234/maps` periodically .... But I am not sure that `time -v` is wrong. I believe it is accurate. I trust more `time` than any graphical system monitor. – Basile Starynkevitch Jan 21 '15 at 13:37
  • No I need program that could determine automatically. But did you read the thread that I sent about gnu time? – carol Jan 23 '15 at 10:26