Two time commands in linux are found in linux Today. in summary, www.2cto.com has two time commands in linux. one is the bash command, the other is the program/usr/bin/time. The bash time command can only display the execution time of the program, while/u... two time commands in linux are found in linux Today. in summary, www.2cto.com has two time commands in linux. one is the bash command, the other is the program/usr/bin/time. The bash time command can only display the execution time of the program, the/usr/bin/time program can display detailed IO-related data, such as how much data is read from the memory and how much data is read from the disk, and the page size of the file system. Through the type command at www.2cto.com, we can see two time oracle @ Linux [] in linux: ~ $ Type-a time is a shell keyword time is/usr/bin/time bash in the time example oracle @ linux []: ~ $ Time echo test real 0m0. 000 s user 0m0. 000 s sys 0m0. the time command in bash s can only display the execution time of your program, including the actual execution time, user time, and system time. There is no other information. The time program is different. It provides detailed information and can also customize the output results of the time program. for details, you can view the output results by using man time, here we only list the data display under the time-v parameter. Oracle @ linux []: ~ $/Usr/bin/time-v echo test Command being timed: "echo test" User time (seconds): 0.00 System time (seconds ): 0.00 Percent of CPU this job got: 0% Elapsed (wall clock) time (h: mm: ss or m: ss. 01 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 se T size (kbytes): 0 Major (requiring I/O) page faults: 113 Minor (reclaiming a frame) page faults: 16 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 ed: 0 Signals delivered: 0 Page size (bytes): 4096 Exit status: 0 from the output, we can see that in addition to the CPU time, we usually care about the following: Major (requiring I/O) page faults The number of pages of data read from the disk. Minor (reclaiming a frame) page faults reads data on how many pages from the operating system cache. The number of times the Swaps process is out of memory. The number of data records that File system inputs/outputs reads/writes from the File system. Page size (bytes) The Page size of the operating system. ------------------------------------ About the three-state in time: Core Mode: in the Kernel Mode, the code has full and unrestricted access to the underlying hardware. Attackers can execute arbitrary CPU commands to access any memory address. The kernel mode is generally run for the underlying, trusted, and reliable code provided by the operating system. The kernel-state code crash will be disastrous, and it will affect the entire system. User Mode: in User Mode, code does not have the ability to directly access hardware or memory, but must rely on the reliability provided by the operating system, the underlying APIs to access hardware or memory. Due to the protection function of this isolation, the user-mode code crashes (Crash) and the system can be restored. Most of our code runs in user mode. Let's take a look at the relationship between the three. there is no strict relationship between the three. common mistakes include: misunderstanding 1: real_time = user_time + sys_time. our incorrect understanding is, real time is equal to user time + sys time. This is incorrect. real time is the time passed by the clock, and user time is the cpu time of the program in the user state, sys time is the cpu time of the program in the core state. Using these three methods, we can calculate the cpu usage during the program running as follows: % cpu_usage = (user_time + sys_time)/real_time * 100% for example: # time sleep 2 real 0m2. 003 s user 0m0. 000 s sys 0m0. s cpu utilization is 0, because it is like this, sleep for 2 seconds, the clock goes through 2 seconds, but the cpu time is 0, so the usage is 0 misunderstanding 2: real_time> user_time + sys_time in general, the above is true, the above situation is often true in the case of a single cpu. However, in the case of multi-core cpu, and the code is really beautiful, you can use all the multi-core cpu, then the above relationship is not true at this time, for example, the following situation may occur, don't be surprised. Real 1m47. 363 s user 2m41. 318 s sys 0m4. 013 s -------------------------
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.