flat assembler
Message board for the users of flat assembler.

Index > Linux > 'time' vs 'nice' vs 'time nice' vs 'nice time'

Author
Thread Post new topic Reply to topic
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20363
Location: In your JS exploiting you and your system
revolution 03 Feb 2020, 11:12
Code:
~ echo Hello World!
Hello World!    
Code:
~ time echo Hello World!
Hello World!

real    0m0.000s
user    0m0.000s
sys     0m0.000s    
Code:
~ nice echo Hello World!
Hello World!    
Code:
~time nice echo Hello World!
Hello World!

real    0m0.008s
user    0m0.000s
sys     0m0.004s    
Code:
~ nice time echo Hello World!
Hello World!
0.00user 0.00system 0:00.00elapsed 0%CPU (0avgtext+0avgdata 1716maxresident)k
0inputs+0outputs (0major+70minor)pagefaults 0swaps    
Why is the last result so different?And the answer is because bash uses its own time code instead of the one at /usr/bin/time
Post 03 Feb 2020, 11:12
View user's profile Send private message Visit poster's website Reply with quote
donn



Joined: 05 Mar 2010
Posts: 321
donn 03 Feb 2020, 18:31
Weird..! Could it be the different time commands?


"Lets not use /usr/bin/time and use ‘time’ instead."

https://www.thegeekstuff.com/2012/01/time-command-examples/

Maybe when you call time directly, it invokes 'time' instead of /usr/bin/time when called by nice. Not sure why nice would call /usr/bin/time, something to do with path search orders maybe?

Going to set Linux back up again sometime this month... the CLI is so different from Powershell and Win. Want to return to it and try some stuff out.
Post 03 Feb 2020, 18:31
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20363
Location: In your JS exploiting you and your system
revolution 04 Feb 2020, 12:46
Yes, you got it right. I hid the answer in the first post.

'time' is both a bash shell internal command, and an external program. And the outputs are different.

When bash interprets the CLI input and sees 'time' ahead of another command it will start its own timer and execute the following command. So "time <command>" only uses the internal time in bash.

But when 'nice' is first on the command line bash simply runs 'nice' and passes the arguments forward. So for "nice time <command>" when 'nice' runs and sees 'time' as the command it finds /usr/bin/time and runs that.

This can be illustrated with:
Code:
~ time nice time echo Hello World!
Hello World!
0.00user 0.00system 0:00.00elapsed 0%CPU (0avgtext+0avgdata 1776maxresident)k
0inputs+0outputs (0major+70minor)pagefaults 0swaps

real    0m0.011s
user    0m0.000s
sys     0m0.004s    
Post 04 Feb 2020, 12:46
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.