Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Time::HiRes strange behavior

by markkawika (Monk)
on Feb 05, 2010 at 22:35 UTC ( [id://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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (5)
As of 2024-09-18 11:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The PerlMonks site front end has:





    Results (24 votes). Check out past polls.

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.