2

I know I can use top to view the overall real-time CPU & Memory usage,
and nload for overall real-time bandwidth usage.

But I wish to view the maximum(or average) CPU, Memory, & bandwidth usage of a program after its running.
Just like time my_command did in program time spend estimation.

Is there a brief way to do that in Linux/Unix?

1
  • There is a program thats called htop that provides a more graphical interpretation of top.. Not sure if it has everything your looking for but definitely worth investigating..
    – ryekayo
    Sep 1, 2015 at 13:37

1 Answer 1

5

If the system supports process accounting, and accounting is enabled, then there may be records available in the process accounting file, e.g. on RedHat Linux:

$ grep -q BSD_PROCESS_ACCT=y /boot/config-* && echo hooray
hooray
$ sudo touch /var/log/pacct
$ sudo accton /var/log/pacct
$
...
$ sudo accton   # turn it off

Parsing the acct(5) file is left as an exercise to the reader.

However, this is global, so may not be suitable for a system with a heavy load of new process creation. Per-process, the getrusage(2) call should yield CPU and memory stats, possibly via a wrapper with the RUSAGE_CHILDREN flag to report on child processes you are interested in.

Network bandwidth may be more difficult to obtain, especially on a per-process basis.

Other tools, such as DTrace or Ftrace may also be of interest.

You must log in to answer this question.

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