Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is user + sys time equal to real/wall clock time?

Tags:

unix

In Perl:

my ($usr,$sys,$cusr,$csys) = times;
printf "real %s, user %s, sys %s\n", $usr + $sys, $usr, $sys;

Is this true? I read some other questions where people did things like saving the current time away in a variable and collecting it later, but why wouldn't this work?

like image 563
dlamotte Avatar asked Dec 30 '25 07:12

dlamotte


2 Answers

No, it is not. User and system time account only for used CPU time. While the program is asleep, real time still passes, but the user and system time stand still. Also, on multi-CPU systems, it may well happen that user+system is greater than real time.

like image 50
zvrba Avatar answered Jan 01 '26 20:01

zvrba


C:\Temp> cat tt.pl
sleep 5;
my ($user, $system) = times;
print "u = $user s = $system\n";


C:\Temp> tt
u = 0.015 s = 0.015
like image 40
Sinan Ünür Avatar answered Jan 01 '26 20:01

Sinan Ünür



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!