6

I know how to monitor a process. Commands like top and so forth can monitor the CPU time and memory usage for a given process instance.

But say I expect a given executable to be run several times in the next hour, and I want to measure how many times it is run and the CPU time it has consumed. What's a command for that?

3

You could do something like:

mv my-executable my-executable.bin

And create my-executable as a wrapper script that does:

#! /bin/bash -
{ time "$0.bin" "$@" 2>&3 3>&-; } 3>&2 2>> /tmp/times.log

The script could add more information to the log like the time it was started, by whom, the arguments it was passed...

BSD process accounting, at least on Linux does report CPU time (user + sys), though not in a cumulative way like time does (children processes CPU time is not accounted for the parent)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.