Time Command meaning

Source: Internet
Author: User
Tags add time

Linux uses the time command to obtain the command execution time
In Linux, the time command can get the execution time of a program, including the actual running time of the Program (real time) and the time when the program runs in the user State (user time) and kernel state time (sys time ). Its usage is similar to the strace mentioned earlier. Just add time before the command to be executed. Let's look at an example program test. c # incl.
In Linux, the time command can get the execution time of a program, including the actual running time of the Program (real time) and the time when the program runs in the user State (user time) and kernel state time (sys time ).
Its usage is similar to the strace mentioned earlier. Just add time before the command to be executed.
Let's look at an example program test. c.
# Include <stdio. h>
Int main ()
{
FILE * fp = fopen ("/tmp/testfile", "w ");
Int I = 0;
For (I = 0; I <3; ++ I)
{
Fprintf (fp, "% dn", I );
}
Fclose (fp );
Return 0;
}
Compile and use the time command to calculate the execution time:
[Leconte @ localhost test] $ time./test
Real 0m0. 020 s
User 0m0. 000 s
Sys 0m0. 018 s
The results show that the actual running time of the program is 0.020 s, the user-mode running time is close to 0 s, and the kernel-mode running time is 0.018s. this is because our main operation is to use file-related system calls, most of the time the program works in the kernel state.
It should be noted that real is not equal to the sum of user + sys. Real represents the full time from the beginning to the end of the program, even if the program does not occupy the CPU, the time is counted. User + sys is the total CPU usage time of the program. This time has nothing to do with the system load. Therefore, real is always greater than or equal to user + sys.
For example, I add sleep (1) in the above program ):
For (I = 0; I <3; ++ I)
{
Sleep (1 );
Fprintf (fp, "% dn", I );
}
The time statistics are as follows:
[Leconte @ localhost test] $ time./test
Real 0m3. 025 s
User 0m0. 000 s
Sys 0m0. 019 s
Since three times of sleep (1) execution, the real time is 3 s longer than just now, and the program in these 3 s does not occupy the CPU, so the user + sys has not changed.

Related Article

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.