Why is sys time 0 here?
-
24-06-2021 - |
Domanda
When I do $(time sleep 1)
, I got:
real 0m1.001s
user 0m0.000s
sys 0m0.000s
I'm not sure why sys
time was 0, so nanosleep
is called from userspace ?
Also, does the real time equals to context switch time + real sleep time (1s) ?
Soluzione
Looking at the man page for time, we can see that,
real : Length of time the program took to terminate, calculated as :
(time at end of program - time at star of program)
user : The sum of the tms_utime and tms_cutime values in a struct tms as returned by times(2)
sys : The sum of the tms_stime and tms_cstime values in a struct tms as returned by times(2)
So the result you are getting effectively means that your program lasted for 1 second and in that 1 second it used 0 seconds as user time and 0 seconds as system time. Which is exactly what we should expect from the program.
When a program is sleeping it just means the kernel will not schedule it for processing, it won't even run no-ops, it just wont run so no system time is consumed.
Altri suggerimenti
Because the process is not executing kernel-space code while it is sleeping. The kernel is executing other processes, or idling, neither of which is influenced by the sleeping process.