Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re: Time::HiRes strange behavior

by markkawika (Monk)
on Feb 05, 2010 at 22:35 UTC ( #821659=note: print w/replies, xml ) Need Help??

in reply to Time::HiRes strange behavior

This is because of how tail -f works.

The way it works is that it reads to the end of a file, outputs that to standard output, and then does a sleep(1);. Then it looks at the file again to see if it's grown. If it has, it reads what's new, outputs it to standard output, then sleeps again. If there's nothing new, it just sleeps.

Either way, it is waking up exactly at 1-second intervals to see if there's new data. That's why the microsecond number is slowly incrementing; the small increment represents the amount of time it took to wake up, read (or not read) data, and then go back to sleep.

tail does this because there is no standard mechanism in Unix for a process to know when a specific file has been changed. There's no signalling mechanism. Some OSes do support this (For example, FreeBSD and OS X have the kqueue system, which will work this way), but it is not standard.

Replies are listed 'Best First'.
Re^2: Time::HiRes strange behavior
by Anonymous Monk on Feb 05, 2010 at 23:12 UTC
    Thanks markkawika. What you've described does indeed appear to be largely related to, if not the entire source of, the problem.
    Of course, now I have to figure out how to satisfy the original goal anyway, but that's another matter entirely. :)
    Thanks for the prompt reply.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://821659]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2020-01-28 06:47 GMT
Find Nodes?
    Voting Booth?