1753622 Members
5701 Online
108797 Solutions
New Discussion юеВ

Two "time" commands?

 
Matt Hearn
Regular Advisor

Two "time" commands?

Hey guys, I'm running HPUX 11.23 on an rx6600, and I'm noticing strange behavior when I use the "time" command. If I specify /usr/bin/time, I get values with one decimal place, and can redirect the stderr:

# /usr/bin/time sleep 3 2>test
# cat test

real 3.0
user 0.0
sys 0.0

If I don't specify the full path, and just use "time" by itself, I get two decimals and the stderr won't redirect:

# time sleep 3 2>test

real 0m3.02s
user 0m0.00s
sys 0m0.00s
# cat test
#

I assumed that there must be two versions of "time" available, and my path finds the 2-decimal one first, but:

# which time
/usr/bin/time

Huh? I'm very confused. Anybody know how I can capture the 2-decimal output of "time"?
14 REPLIES 14
Pete Randall
Outstanding Contributor

Re: Two "time" commands?

Matt,

Sure seems like two different commands. Try "whence time", "whereis time", "type time" to see if you can find something other than /usr/bin/time.


Pete

Pete
James R. Ferguson
Acclaimed Contributor

Re: Two "time" commands?

Hi:

There is 'time' and 'timex'. One posibility is that your 'time' has been aliased to 'timex'.

# alias time timex

As Pete suggesed, do:

# whence -v time

You might see:

time is an alias for timex

Regards!

...JRF...
Matt Hearn
Regular Advisor

Re: Two "time" commands?

# whence time
time
# whereis time
time: /usr/bin/time /usr/share/man/man1.Z/time.1 /usr/share/man/man2.Z/time.2
# type time
time is a keyword

I do have an alias that "type=whence -v", for whatever reason.
Torsten.
Acclaimed Contributor

Re: Two "time" commands?

What is your shell? ksh?

Sounds like a solution:

http://docs.hp.com/en/B2355-60103/ksh.1.html

...

time pipeline
pipeline is executed and the elapsed time, user time, and system time are printed on standard error. Note that the time keyword can appear anywhere in the pipeline to time the entire pipeline. To time a particular command in a pipeline, see time(1).

...

Hope this helps!
Regards
Torsten.

__________________________________________________
There are only 10 types of people in the world -
those who understand binary, and those who don't.

__________________________________________________
No support by private messages. Please ask the forum!

If you feel this was helpful please click the KUDOS! thumb below!   
Pete Randall
Outstanding Contributor

Re: Two "time" commands?

> "time is a keyword"

That's interesting (maybe). On my 11.11 box, I get:

# type time
time is /usr/bin/time

Does anybody know what is meant by "keyword"?


Pete

Pete
Patrick Wallek
Honored Contributor

Re: Two "time" commands?

>>Does anybody know what is meant by "keyword"?

That means it is a shell built-in command.

Try doing a 'type while' and you will get the same thing.

I'm not sure why you'd be getting that in this case though.
Pete Randall
Outstanding Contributor

Re: Two "time" commands?

Ahhhh, I see! It's a shell keyword. Right in the man page:

"Note that the shell also has a keyword time that times an entire pipeline if used anywhere in the pipeline, unlike time(1) command which times a particular command if used in a pipeline."

So your first result is from the command /usr/bin/time and the second result is from the shell (ksh or csh, by the way) keyword.


Pete

Pete
Torsten.
Acclaimed Contributor

Re: Two "time" commands?

with sh:

# whence time
/usr/bin/time

# type time
time is /usr/bin/time


with ksh:

# whence time
time

# type time
time is a keyword


Sounds reasonable ...

Hope this helps!
Regards
Torsten.

__________________________________________________
There are only 10 types of people in the world -
those who understand binary, and those who don't.

__________________________________________________
No support by private messages. Please ask the forum!

If you feel this was helpful please click the KUDOS! thumb below!   
James R. Ferguson
Acclaimed Contributor

Re: Two "time" commands?

Hi (again):

What shell are you using?

For the Posix shell (on a PA-RISC 11.23 box), a shell-builtin (like 'test') looks like:

# whence -v time
time is /usr/bin/time
# whence -v test
test is a shell builtin.

It would be interesting to see your shell aliases too:

# alias

Regards!

...JRF...