I am aware that the output of the time
command can show greater time under the user
section than the real
section for multi-processor cases, but recently, I was trying to profile a program when I saw that real
was substantially greater than user
+ sys
.
$ time ./test.o
real 0m5.576s
user 0m1.270s
sys 0m0.540s
Can anybody explain why such a behaviour is caused?
The output of the time command also includes the CPU seconds the executable uses in the user and the kernel modes. So, in the above example, the CPU time spent in the user mode was 0.001 seconds and the CPU time spent in the kernel mode was 0.002 seconds.
time command in Linux is used to execute a command and prints a summary of real-time, user CPU time and system CPU time spent by executing a command when it terminates.
3.1. These are executed in kernel mode. All other commands are executed in user mode. user time represents the time that a command has executed in user mode. In our case, that was precisely 0.063 seconds.
'user' time is the CPU time spent in user-mode code (outside the kernel). 'Sys' time is the amount of CPU time spent in the kernel. This means executing CPU time spent in system calls within the kernel, as opposed to library code, which is still running in user-space.
That's the normal behavior.
"Real" is is the wall-clock time. In your example, it literally took 5.576 seconds to run './test.o'
'user' is the User CPU time, or (roughly) CPU time used by user-space processes. This is essentially the time your CPU spent actually executing './test.o'. 1.270 seconds.
And finally, 'sys' is System CPU time, or (roughly) CPU time used by your kernel. 0.540 seconds.
If you add sys + user, you get the amount of time your CPU had to spend executing the program.
real - (user + sys) is, then, the time spent not running your program. 3.766 seconds were spent between invocation and termination not running your program--probably waiting for the CPU to finish running other programs, waiting on disk I/O, etc.
Time your process spends sleeping (e.g., waiting for I/O) is not counted by either "user" or "system", but "real" time still elapses.
Try:
time cat
...then wait 10 seconds and hit ctrl-D.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With