Explain the use of Linux time command in detail

  • 2021-08-28 21:35:25
  • OfStack

1. Brief introduction to commands

time is used to count the time consumed by command execution and related system resources. There are four major resources that time can display, namely:

Time resources
Memory resources
IO resources
Command info

2. Command format


time [options] command [arguments...]

3. Description of options


-f FORMAT, --format=FORMAT Output in the specified format. If no output format is specified, use the environment variable  TIME  The specified format 
-p, --portability Using compatible output formats, real %e user %U sys %S The purpose of doing this is to communicate with  POSIX  Specification compatibility 
-o FILE, --output=FILE Set the result output file. This option sets the  time  Writes the output of to the specified file. If the file already exists, overwrite its contents 
-a, --append : With  -o  Options 1 Use append mode to write the output to the specified file 
-v, --verbose Use redundancy mode to output statistics as much as possible 
--help Display Help Information 
-V, --version Display version information 
--  Terminate the list of options 

The output format is interpreted in a similar way to printf, and ordinary characters will be output directly. Tab characters, newline characters and backslash percent signs are represented by\ t,\ n,\ and%% respectively. The% followed by other letters indicates a special format. The available formats are as follows:


Time
%E Time spent executing instructions, format [hours:]minutes:seconds
%e Time, in seconds, taken to execute an instruction 
%S Instruction execution in kernel mode ( kernel mode ) The time spent, in seconds 
%U Instructions are executed in user mode ( user mode ) The time spent, in seconds 
%P : When executing instructions  CPU  The occupancy ratio of. In fact, this number is kernel mode plus user mode  CPU  Time divided by total time ( (%S+%U)/%E ) 

Memory
%M Maximum amount of memory occupied during execution. Unit KB
%t Average value of memory used during execution, in  KB
%K Total amount of memory used to execute the program ( stack+data+text ), in units of  KB
%D Own data area of the executing program ( unshared data area ), in units of  KB
%p Execute the program's own stack ( unshared stack ), in units of  KB
%X The executor is a shared code snippet ( shared text ), in units of  KB
%Z The size of the system memory page in  byte . Antithesis 1 This is a constant for a system 
%F Number of memory page errors. Memory page error refers to the need to read data from disk to memory 
%R Number of minor or recoverable page errors. These are errors for invalid pages, but the memory page has not been used by other virtual pages. Therefore, the data in the page is still valid, but the system tables must be updated 
%W Number of times a process swaps from memory 
%c : The number of times the process context was switched (because the time slice has expired) 
%w Process wait times, which refers to the number of times the program actively switches context, such as waiting I/O Operation complete 

I/O
%I Number of files entered by this program 
%O Number of files output by this program 
%r Objects received by this program  Socket Message
%s Object sent by this program  Socket Message
%k Signals received by this program  ( Signal ) Quantity 

Command Info
%C Parameters and instruction names at execution time 
%x End code of instruction  ( Exit Status )

4. Common examples

(1) Count the execution time of specified commands.


time date 
Fri May 31 11:30:04 CST 2019

real	0m0.001s
user	0m0.000s
sys		0m0.000s

The above is a detailed explanation of the use of Linux time command details, more information about Linux time command please pay attention to other related articles on this site!


Related articles: