What do 'real', 'user' and 'sys' mean in the output of time(1)?

The time(1) command on Unix-like systems is used to measure the execution time of a command. The output of time is typically divided into three parts: "real", "user", and "sys", each providing different insights into the time taken by the command.

Here's what each of these components means:

    Real Time (real):
        The "real" time represents the actual time that has passed from the start of the command execution to its completion. It includes all the time spent by the command, including time spent waiting for I/O operations, system overhead, and other external factors.

    User Time (user):
        The "user" time indicates the amount of CPU time spent in the user mode during the command's execution. It measures the time spent executing the user-level code of the command itself.

    System Time (sys):
        The "sys" time represents the amount of CPU time spent in the kernel (system) mode during the command's execution. It measures the time spent executing system-level operations, such as file I/O, memory management, and other kernel-related tasks.

Here's an example of how you might use time(1) to measure the execution time of a command:

bash

time ls -l

Sample output:

sql

real    0m0.020s
user    0m0.002s
sys     0m0.005s

In this example, the real time is the total time elapsed during the ls -l command's execution. The user time and sys time represent the time spent in the user and system modes, respectively.

Keep in mind that the real time can be affected by various factors, including system load, I/O operations, and other processes running on the system, so it might not always be consistent. The user and sys times are generally more indicative of the computational load that the command places on the system.

Comments