How to summarize detailed system resource usage for given command on a Linux or Unix

How do I determine the system resource usage during of execution of a particular command on a Linux, OS X Unix, BSD and Unix-like operating system?

You need to use /usr/bin/time (hereinafter referred to as “time”) command to find the system resource usage during of execution of a particular command. The following information can be obtained from the “time” command:

  1. User time
  2. System time
  3. Percent of CPU this command got
  4. Elapsed time
  5. Average shared text size
  6. Average unshared data size
  7. Average stack size
  8. Average total size
  9. Maximum resident set size
  10. Average resident set size
  11. Major (requiring I/O) page faults
  12. Minor (reclaiming a frame) page faults
  13. Voluntary context switches
  14. Involuntary context switches
  15. Swaps
  16. File system inputs
  17. File system outputs
  18. Socket messages sent
  19. Socket messages received
  20. Signals delivered
  21. Page size (bytes)
  22. Exit status

The above describing the resources utilized by the current process or command and can be obtained by “time” command. It is defined as follows in sys/resource.h

/* taken from OSX/FreeBSD unix */
     struct rusage {
             struct timeval ru_utime; /* user time used */
             struct timeval ru_stime; /* system time used */
             long ru_maxrss;          /* max resident set size */
             long ru_ixrss;           /* integral shared text memory size */
             long ru_idrss;           /* integral unshared data size */
             long ru_isrss;           /* integral unshared stack size */
             long ru_minflt;          /* page reclaims */
             long ru_majflt;          /* page faults */
             long ru_nswap;           /* swaps */
             long ru_inblock;         /* block input operations */
             long ru_oublock;         /* block output operations */
             long ru_msgsnd;          /* messages sent */
             long ru_msgrcv;          /* messages received */
             long ru_nsignals;        /* signals received */
             long ru_nvcsw;           /* voluntary context switches */
             long ru_nivcsw;          /* involuntary context switches */


The syntax is as follows on Linux:

/usr/bin/time -v command
/usr/bin/time -v command arg1 arg2

The syntax is as follows on FreeBSD or OS X unix:

/usr/bin/time -l command
/usr/bin/time -l command arg1 arg2


Let us run host command on Linux to find out the resources utilized by the host command during execution:
$ /usr/bin/time -v host
Sample outputs:

Fig.01: Determine the duration of execution of a particular command on Linux with resource utilization

Let us run date command on OS X or FreeBSD Unix based system to find out the resources utilized by the date command during execution:
$ /usr/bin/time -l date
Sample outputs:

Fig.02: Determine the duration of execution of a particular command on Unix/OSX

A note about “/usr/bin/time” and time command

  1. time is a shell command.
  2. /usr/bin/time is an external command and provides additional information such as the resources utilized by a particular command.

For more information see man pages ksh(1).

Posted by: SXI ADMIN

The author is the creator of SXI LLC and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.