1

I am wondering if there is any way to compare the peak memory usage of different process in bash script. I want to compare the memory usage of different program which are working in the same data set. my bash file is something like below:

 #!/bin/bash
 ./program_1 parameterSet1
 ./program_2 parameterSet2
 ./program_3 parameterSet3

I want to store the max memory usage of each process separately. It might be useful to point out that each program takes several minutes to finish, how can i monitor max memory usage of that program simultaneously. Should I write another bash script?

Many thanks in advance

user2373198
  • 147
  • 10
  • possible duplicate of [Peak memory usage of a linux/unix process](http://stackoverflow.com/questions/774556/peak-memory-usage-of-a-linux-unix-process) – hek2mgl Feb 18 '15 at 15:37

1 Answers1

2
/usr/bin/time -f "process 1 max RSS %M kbytes" ./program1 parameterSet1
/usr/bin/time -f "process 2 max RSS %M kbytes" ./program2 parameterSet2

Will put the maximum resident set size on stderr for the program. You can tailor the format string (as I did) or redirect outputs to trace each separate process.

mpez0
  • 2,815
  • 17
  • 12
  • Woow, it works. thanks. would you please tell me how can i put the memory usage in a variable to use it later? – user2373198 Feb 18 '15 at 16:07
  • Assuming you either don't need the stdout or can save it as a separate file, `rss=$(/usr/bin/time -f "%M" ./program1 parameterSet1 2>&1 >program1.out)`. If you don't need the output, make "program1.out" be "/dev/null". – mpez0 Feb 18 '15 at 16:19