Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Is a file currently being modified?

by davido (Cardinal)
on Aug 16, 2005 at 23:39 UTC ( #484278=note: print w/replies, xml ) Need Help??


in reply to Is a file currently being modified?

Assuming other applications visiting this logfile are playing nice too, you could use flock with the LOCK_NB bitflag set (that is Lock Non-Blocking). This will cause flock to return immediately instead of waiting for a lock. When it returns, its status will tell you whether it was granted a lock or not. If not, you know something else has the file locked. Flocking is voluntary, so scripts/programs that don't lock the file or check to see if it's locked won't play nice with applications that do.

As far as reading lines as they're being written, that's precarious. Due to buffering, you're unlikely to get line by line info, but rather chunks every so often.

By the way, another option would be to periodically check last modification time, or file size. A change there will indicate the file has been written to.


Dave

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2023-03-26 19:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which type of climate do you prefer to live in?






    Results (63 votes). Check out past polls.

    Notices?