Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: How do I block until new data has been added to a file?

by kjherron (Pilgrim)
on Aug 16, 2001 at 19:04 UTC ( #105400=note: print w/replies, xml ) Need Help??


in reply to How do I block until new data has been added to a file?

A unix-specific answer: Unix doesn't provide a mechanism to do what you ask. select() and poll() are just telling you that you can perform a read() without blocking, and reading from a file never blocks. Even the "tail -f" command works by alternately sleeping and checking the file that it's tailing.

If you're worrying about wasting CPU or something like that, I suggest you shouldn't be concerned about it; waking up once a second or so and performing a read() isn't going to burden the computer. If you need to get this working for some other reason, here's an idea: spawn a subprocess to read from the file, copying everything that it reads to a pipe being read by the main process. This gives you something the main process can select() on.

  • Comment on Re: How do I block until new data has been added to a file?

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2021-04-18 22:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?