Home » 2014 » October » 6 » Time command in Linux to give resource usage

1:27 AM
Time command in Linux to give resource usage

Share on Google+

TIME a simple command to give resource usage in Linux system

FORMAT
       time [options] command [arguments...]


DESCRIPTION
       The  time command runs the specified program/command with the given arguments.  When command finishes, time writes a message to standard error giving timing statistics about the program run.  

These statistics consist  of  real time and CPU time

  1. The elapsed real time between invocation and termination of the command
  2. The user CPU time (the sum of the tms_utime and tms_cutime values in a struct tms as returned by times(2))
  3. The system CPU time (the sum of the tms_stime and tms_cstime values in a struct tms as returned by times(2)).

The CPU time is divided into user time and system time

User time :- time used by the program itself and any library subroutines it calls
System time :- time used by the system calls invoked by the program (directly or indirectly)

 


Example:

[shanky@HYDBMW ~]$ time ll
total 16
-rw-rw-r--. 1 shanky shanky   22 Sep 19 11:08 abc.tmp
-rw-rw-r--. 1 shanky shanky   74 Sep  6 17:36 chat
lrwxrwxrwx. 1 shanky shanky   16 Sep  6 18:15 chat1.sh -> /usr/bin/chat.sh
-rwxr-xr-x. 1 shanky shanky 3705 Sep 13 19:48 chatbackup.sh
-rwxrwxr-x. 1 shanky shanky 1437 Sep  7 17:58 chat.sh

real    0m0.007s
user    0m0.000s
sys     0m0.006s  

In above example the "ll" command was executed and its time statistics is displayed.


GNU Options
       -f FORMAT, --format=FORMAT
              Specify output format, possibly overriding the format specified in the environment variable TIME.

       -p, --portability
              To get the portable output format. When the -p option is given the (portable) output format is:

           real %e
           user %U
           sys %S

[shanky@HYDBMW ~]$ time -p cal
    October 2014
Su Mo Tu We Th Fr Sa
          1  2  3  4
 5  6  7  8  9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31

real 0.02
user 0.00
sys 0.01

Descriptions are as given below:

       %E     Elapsed real time (in [hours:]minutes:seconds).

       %e     (Not in tcsh.) Elapsed real time (in seconds).

       %S     Total number of CPU-seconds that the process spent in kernel mode.

       %U     Total number of CPU-seconds that the process spent in user mode.

       %P     Percentage of the CPU that this job got, computed as (%U + %S) / %E.


     -o FILE, --output=FILE
              It will not send the results to stderr, but will overwrite to the specified file.

       -a, --append
              (Used together with -o.) It will not overwrite but append to the specified file.

 

The TIME command is also used for resources like  memory,  I/O and IPC calls (where available).  The output is formatted using a format string that can be specified using the -f option or the TIME environment variable.

The default format string is:

%Uuser %Ssystem %Eelapsed %PCPU (%Xtext+%Ddata %Mmax)k
%Iinputs+%Ooutputs (%Fmajor+%Rminor)pagefaults %Wswaps

      

Note:  some  shells  (e.g., bash(1)) have a built-in time command that provides less functionality than the command described here.  

To access the real command, you may need to specify its pathname  (something  like /usr/bin/time).


You may also like to see:


 
 

Category: Open System-Linux | Views: 1516 | Added by: shanky | Tags: time in linux, time command in unix, find resource usage of a command in, time command in linux, time command example in linux | Rating: 0.0/0

Related blogs


You may also like to see:


[2014-03-12][Open System-Linux]
uptime command in Linux
[2014-11-25][Open System-Linux]
DMESG command in Linux : to display or control kernel ring buffer
[2014-09-21][Open System-Linux]
How to define command prompt strings in Linux : what are $PS1, $PS2, $PS3 and $PS4?
[2014-10-25][Open System-Linux]
XMLWF command in Linux to check/validate/parse an XML file
[2017-08-13][Open System-Linux]
Perl trick to remove Ctrl - M charater from a file

Total comments: 0
ComForm">
avatar