Updated April 14, 2023
Introduction to Linux Time
In the Linux operating system, the time will run the special program with a specific or compatible input argument. When the command or the job will finish the execution, the time command will give the below timing statistics
- Elapsed Time: It is the passed time between the invocation of the process or job and the termination of the process.
- User CPU Time: It is the addition of the tms_utime time and tms_cutime time values.
- System CPU Time: It is the addition of the tms_stime time and tms_cstime time values.
Note: Some login shell environments have the build-in time functionality. But it will not provide more information. If we need more information about it, we need to use the time command full path i.e. /usr/bin/time.
time [ OPTION ] [ COMMAND ]
- time : We can use the “time” keyword in the syntax or command. It will take different arguments like options and commands. As per the provided arguments, it will print the time options in different types like Elapsed Time, User CPU Time, and System CPU Time.
- OPTION : We can provide the different flags as the option that is compatible with the “time” command.
- COMMAND: As per the condition or requirement, we can provide or use a different command with the time keyword.
How Linux Time Works?
Linux is a multi-user support operating system. It will support multiple servers or applications. While running these servers or applications, they are generating a huge amount of data. Once the data will generate parallel the time will also increase while doing the reading or writing operations on it. The time command will consider the different compatible options with the command. As per the inputs, it will give the detailed information of time in terms of the Elapsed Time, User CPU Time, and System CPU Time.
Below are the lists of options that are compatible with the time command.
|1||C||It will give the information of the name and the command line arguments being timed (in terms of the command)|
|2||D||It will give information about the average size of the processes in the unshared data area. The information will be in Kilobytes.|
|3||E||This process will use the wall clock time. It will be in hours: minutes: seconds format.|
|4||I||It will get the Number of file system inputs by the process.|
|5||K||It will consider the average of data, stack, and text memory use of the process. It will be in Kilobytes.|
|6||M||Due to the process lifetime, we can set the maximum resident of the process. It will be in Kilobytes.|
|7||O||The process will consider the number of file system outputs.|
|8||P||It is the addition of user and system time divide by total running time. We will get the percentage of the CPU that the job got.|
|9||S||In terms of process, it will be the total number of CPU-seconds used by the system. The value will be in seconds.|
|11||W||It will give the memory information of the number of times the process was swapped.|
|12||X||It will give information on the average amount of shared text in the process. The value will be in Kilobytes.|
|13||Z||It will give the system page size information. The value will be in bytes.|
|14||e||It will be the wall clock time used by the process. The value will be in seconds.|
|15||k||It will give the information of the number of signals delivered to the process.|
|16||p||It will give the process information of the average unshared stack size. The value will be in Kilobytes.|
|17||r||The process will receive the number of socket messages.|
|18||s||The process will be sent the number of socket messages.|
|19||t||It will give the information of the average resident set size of the process. The value will be in Kilobytes.|
|20||x||It will give the exit status of the command.|
Lets us discuss examples of Linux time.
In the Linux environment, we can run the simple time command and get the basic information of the Elapsed Time, User CPU Time, and System CPU Time.
As per the above command, we are running the simple time command. It will give the basic information of the Elapsed Time, User CPU Time, and System CPU Time.
In the time command, we are having the functionality to use the different Linux commands.
time wget https://newton.ex.ac.uk/handbook/PHY/forms/WLB010919-4.pdf
We are using the wget command with the time command. Time command will calculate the elapsed time, user and CPU time for execution of the command.
Example #3 – Redirect Time Command Output
In the time command, we are able to redirect the time command output to a different file.
(time wget https://newton.ex.ac.uk/handbook/PHY/forms/WLB010919-4.pdf) 2> time.txt
As per the above command, we are redirecting the time command output to the “time.txt” file. It will use for further analysis.
Example #4 – With Option “-p”
In time command, we are able to print the time in POSIX format
time -p wget https://newton.ex.ac.uk/handbook/PHY/forms/WLB010919-4.pdf
In the above command, we are able to print the time command output in POSIX format. As per the requirement, we can use the different options with the time command.
We have seen the uncut concept of “Linux Time” with the proper example, explanation, and command with different outputs. As per the requirement, we can use the time command with different Linux command and get detail time information in terms of the Elapsed Time, User CPU Time, and System CPU Time.
We hope that this EDUCBA information on “Linux Time” was beneficial to you. You can view EDUCBA’s recommended articles for more information.