YouTip LogoYouTip

Linux Comm Time

[![Image 1: Linux Command Manual](#) Linux Command Manual](#) 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, etc. It is important to note that some information cannot be displayed on Linux. This is because on Linux, some resource allocation functions differ from the default method used by the time command, preventing the time command from obtaining this data. ### Syntax time COMMAND **Parameters**: * -o or --output=FILE: Set the output file for the results. This option writes the time output to the specified file. If the file already exists, the system will overwrite its contents. * -a or --append: Used with -o, this appends the results to the end of the file without overwriting the existing content. * -f FORMAT or --format=FORMAT: Set the display format using the FORMAT string. When this option is not set, the system's default format is used. However, you can set this format using the environment variable TIME, so you don't have to set it every time you log in. **The time command can display resources in four categories**: * Time resources * Memory resources * IO resources * Command info **Detailed content is as follows**: 1、Time Resources E Time spent executing the command, formatted as: :minute:second. Please note that this number does not represent actual CPU time. e Time spent executing the command, in seconds. Please note that this number does not represent actual CPU time. S Time spent in kernel mode during command execution, in seconds. U Time spent in user mode during command execution, in seconds. P Percentage of CPU used during command execution. This number is actually the sum of kernel mode and user mode CPU time divided by the total time. 2、Memory Resources M Maximum resident set size (physical memory) used during execution, in KB. t Average resident set size (physical memory) used during execution, in KB. K Average total program size (stack+data+text) in KB. D Average size of the unshared data area in KB. p Average size of the unshared stack in KB. X Average size of shared text in KB. Z System memory page size, in bytes. This is a constant for a given system. 3、IO Resources F Number of major page faults (I/O required). A major page fault occurs when a page has been swapped to the swap file and already allocated to another process. The content must be read back from the swap file. R Number of minor page faults (reclaiming a frame). A minor page fault occurs when a page has been swapped but not yet allocated to another process. The content is not destroyed and doesn't need to be read from the swap file. W Number of times the process was swapped out. c Number of times the process was context-switched involuntarily (e.g., time slice expired). w Number of times the process was context-switched voluntarily (e.g., waiting for I/O to complete, like disk reads). I Number of file system inputs by the process. O Number of file system outputs by the process. r Number of socket messages received by the process. s Number of socket messages sent by the process. k Number of signals delivered to the process. 4、Command Info C Command name and arguments. x Exit status of the command. -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 resources used by the program in plain English sentences with explanations. It is very useful for those who don't want to spend time learning format strings or are new to the command. ### Examples 1. # time date2. Sun Mar 26 22:45:34 GMT-8 20063. 4. real 0m0.136s5. user 0m0.010s6. sys 0m0.070s7. # In the example above, the command "time date" is executed (see line 1). The system first executes the "date" command. Line 2 is the output of the "date" command. Lines 3-6 are the time statistics for executing the "date" command. Line 4 "real" is the actual (wall clock) time, line 5 "user" is the user CPU time, and line 6 "sys" is the system CPU time. The display format for all three times is MMmNN[.FFF]s. Using the following command time -v ps -aux we can obtain the results of executing "ps -aux" and the system resources used. 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 root 3 0.0 0.0 0 0 ? SW Apr19 0:00 ...... 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.05System time (seconds): 0.06Percent of CPU this job got: 68%Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.16Average shared text size (kbytes): 0Average unshared data size (kbytes): 0Average stack size (kbytes): 0Average total size (kbytes): 0Maximum resident set size (kbytes): 0Average resident set size (kbytes): 0Major (requiring I/O) page faults: 238Minor (reclaiming a frame) page faults: 46Voluntary context switches: 0Involuntary context switches: 0Swaps: 0File system inputs: 0File system outputs: 0Socket messages sent: 0Socket messages received: 0Signals delivered: 0Page size (bytes): 4096Exit status: 0 [![Image 2: Linux Command Manual](#) Linux Command Manual](#)
← Os AccessOs File Methods β†’