Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Linux time command

Linux time command

Linux Command Reference Linux Command Reference

The purpose of the Linux time command is to measure the time and system resources consumed when executing a specific command.

For example, CPU time, memory, input/output, and so on. It should be noted that some information cannot be displayed on Linux. This is because on Linux the resource allocation functions differ from the default method assumed by the time command, so the time command cannot obtain this data.

Syntax

time [options] COMMAND [arguments]

Parameters:

The time command can display resources in four main categories, namely:

The details are as follows:

1. Time Resources

E The time spent executing the command, in the format [hour]:minute:second. Note that this number does not represent the actual CPU time.

e The time spent executing the command, in seconds. Note that this number does not represent the actual CPU time.

S The time spent in kernel mode during command execution, in seconds.

U The time spent in user mode during command execution, in seconds.

P The CPU usage ratio during command execution. This number is actually the CPU time in kernel mode plus user mode divided by the total time.

2. Memory Resources

M The maximum amount of physical memory used during execution. The unit is KB

t The average amount of physical memory used during execution, in KB

K The average size of the total memory (stack+data+text) used by the executed program, in KB

D The average size of the program's unshared data area, in KB

p The average size of the program's unshared stack, in KB

X The average amount of shared text among executed programs, in KB

Z The size of a system memory page, in bytes. This is a constant for a given system

3. IO Resources

F The number of major memory page faults for this program. A major memory page fault occurs when a memory page has been swapped to the swap file and allocated to another program. In this case, the page's content must be read back from the swap file.

R The number of minor memory page faults for this program. A minor memory page fault occurs when a memory page has been swapped to the swap file but has not yet been allocated to another program. In this case, the page's content is not corrupted and does not need to be read from the swap file

W The number of times this program was swapped to the swap file

c The number of times this program was involuntarily interrupted (such as when its allocated CPU time ran out)

w The number of times this program was voluntarily interrupted (such as waiting for an I/O operation to complete, like a disk read)

I The number of files input by this program

O The number of files output by this program

r The Socket Messages received by this program

s The Socket Messages sent by this program

k The number of signals received by this program

4. Command Info

C The arguments and command name at execution time

x The command's exit status

-p or --portability: This option automatically sets the display format to:

real %e user %Usys %S: This is done for compatibility with the POSIX specification.

-v or --verbose: This option lists all the resources used by the program, not only in plain English but also with descriptions. It is quite useful for those who don't want to spend time learning the format settings or who are just getting started with this command.

Example



1. # time date

2. Sun Mar 26 22:45:34 GMT-8 2006

3. 

4. real    0m0.136s

5. user    0m0.010s

6. sys     0m0.070s

7. #

In the example above, the command "time date" is executed (see line 1).

The system first executes the command "date"; line 2 is the result of the "date" command.

Lines 3-6 are the time statistics for the "date" command, where line 4 "real" is the actual time, line 5 "user" is the user CPU time, and line 6 "sys" is the system CPU time.

All three times above are displayed in the format MMmNN[.FFF]s.

Using the following command

time -v ps -aux

we can obtain the result of executing ps -aux and the system resources consumed, as shown in the data listed below:



USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND

root 1 0.0 0.4 1096 472 ? S Apr19 0:04 init

root 2 0.0 0.0 0 0 ? SW Apr19 0:00 [kflushd]

root 3 0.0 0.0 0 0 ? SW Apr19 0:00 [kpiod]

......

root 24269 0.0 1.0 2692 996 pts/3 R 12:16 0:00 ps -aux

Command being timed: "ps -aux"

User time (seconds): 0.05

System time (seconds): 0.06

Percent of CPU this job got: 68%

Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.16

Average shared text size (kbytes): 0

Average unshared data size (kbytes): 0

Average stack size (kbytes): 0

Average total size (kbytes): 0

Maximum resident set size (kbytes): 0

Average resident set size (kbytes): 0

Major (requiring I/O) page faults: 238

Minor (reclaiming a frame) page faults: 46

Voluntary context switches: 0

Involuntary context switches: 0

Swaps: 0

File system inputs: 0

File system outputs: 0

Socket messages sent: 0

Socket messages received: 0

Signals delivered: 0

Page size (bytes): 4096

Exit status: 0

Linux Command Reference Linux Command Reference