Linux Command Detailed-time__linux

Source: Internet
Author: User
Tags posix

http://blog.csdn.net/thinkerabc/article/details/647272

Command time-execute the command and timing

Format time [P] command [arguments ...]

Description

Executes the command-line command [arguments], which prints the results of the time statistic that executes the command line in standard output at the end of the command line, and its statistical results contain the following data:

1 actual time: From the command line to start execution to the end of the elapsed time;

2 User CPU Time: The user CPU time of the command execution to complete the time spent on the user, that is, the execution of the command in the state of the total;

3 System CPU Time: The command execution completes the cost of the system CPU time, that is, the command in the nuclear mentality of the total execution time.

Where user CPU time and system CPU time are CPU time, that is, the total time that the command consumes CPU execution. The actual time is greater than the CPU time, because Linux is a multitasking operating system, and often the system handles other tasks while executing a command.

Another issue to note is that even though the same command is executed each time, the time spent is different, and the time spent is related to system operation.

Example 1:

1. # Time Date
2. Sun Mar 22:45:34 GMT-8 2006
3.
4. Real 0m0.136s
5. User 0m0.010s
6. SYS 0m0.070s
7. #

In Example 1, execute the command "time Date" (see Line 1th). The system executes the command "date" first, and the execution result of the 2nd behavior command "date". The 第3-6 behavior executes the time statistic result of the command "date", where line 4th "real" is the actual time, the 5th line "user" is the user's CPU time, and the 6th line "SYS" is the system CPU time. The display format for the above three types of time is mmmnn[. Fff]s.

In Example 1, CPU time = User CPU time + system CPU time = 0m0.010s + 0m0.070s = 0m0.080s, the actual time is greater than CPU time, indicating that there are other tasks running while the date command is running.

"Parameter description"

-P Prints the time statistic results, in seconds, in POSIX default time format. The detailed output format is shown in Example 2.

Example 2:1. # time-p Date
2. Wed Mar 00:33:11 GMT-8 2006
3. Real 0.11
4. User 0.00
5. SYS 0.02
6. #

In Example 2, the same command "time Date" is executed (see line 1th). The system executes the command "date" first, and the 2nd acts the execution result of the command. 第3-5 behavior executes the time statistic result of the command "date". Note that the time format of this example differs from the time format in Example 1, and the time displayed with the-p parameter is NN.FF, and the unit is seconds.

"Description of related environment variables"

TimeFormat the time format for custom output.

We can also use the environment variable TimeFormat to customize the output time format [1]. The format uses an escape character that is consistent with the function in standard C, and uses the following escape sequence to specify the time format for the output:

	%[prec][l][rus]

Where the option Prec is the specified time precision, which is the number of digits after the decimal point, and option L means seconds (in the form of: mmmnn[. fff]s) format; The last character represents the type of time, where R represents the actual time, and U represents the user's CPU time, and S represents the system CPU time, each of which is seconds.

The time command defaults to output the timeformat=$ '/nreal/t%3lr/nuser/t%3lu/nsys/t%3ls '.

The time format for output with the-p parameter is the same as the timeformat=$ ' real%2r/nuser%2u/nsys%2s '.

Example 3:1. # export timeformat=$ ' real%2r/nuser%2u/nsys%2s '
2. # time Date
3. Wed Mar 00:52:03 GMT-8 2006
4. Real 0.04
5. User 0.00
6. SYS 0.01
7. #

Comparing cases 2 and 3 shows the results, it is easy to find that example 3 does not use the parameter-p, but its output is identical to that of Example 2.

Of course, we can also modify the format for any time that you like.

Example 4:1. # export timeformat=$ '/nhello, thinkerabc!/nreal time:%lr/nuser CUP time:%lu/nsystem CPU time:%ls '
2. # time Date
3. Wed Mar 01:09:26 GMT-8 2006
4.
5. Hello, thinkerabc!
6. Real Time:0m0.016s
7. User CUP time:0m0.006s
8. System CPU time:0m0.008s
9. #

The 第4-8 line in Example 4 is our custom output format.

From the above, the three methods for specifying the time format, the default time format, the POSIX default time format using the parameter-p, and setting the environment variable TimeFormat custom time format, are used in the following order of Linux systems:

1. POSIX default time format for parameter-p;

2. Environment variable TimeFormat custom time format;

3. The default time format.

"Exit Status description"

If the command command can be executed, it returns the exit status of the order, otherwise the following exit status value is returned:

127 Command not found

126 command found, but not executed

1-125 Other errors

Reference documents:

[1] bash-2.05b source program, http://ftp.gnu.org/gnu/bash/bash-2.05b.tar.gz, 2002.07

[2] Linux man pages

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.