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

Re: Waiting for a file to be written

by moritz (Cardinal)
on Oct 14, 2008 at 13:31 UTC ( #716983=note: print w/replies, xml ) Need Help??

in reply to Waiting for a file to be written

I'm pretty sure that the problem isn't that my_file.txt isn't fully written when you call system, but rather that it's modified by the next iteration of the parent script before the child script reads it fully.

The solution is to either use locking, or not to spawn the child script in the background.

(If you want to learn more about locking Super Search for it, we had many discussion about that).

Replies are listed 'Best First'.
Re^2: Waiting for a file to be written
by why_bird (Pilgrim) on Oct 14, 2008 at 13:56 UTC

    Yes, of course you are right, according to my own output!

    Thanks for the correction, and suggestions :)

    I need to run the child processes in the background (it's a series of long jobs controlled by a queue manager) so I will look into locking. sleep(10) works too, though it's a rough hack...
    Those are my principles. If you don't like them I have others.
    -- Groucho Marx
      Trivial 2-party locking mechanism:
      Why not have the child delete the file when it is finished with it?
      The parent can then wait for the file to disappear before creating the next version of it.

        Another option would be to use Linux::Inotify2 if the operating system is Linux. The trigger would be on IN_CLOSE_WRITE "writable fd to file / to object was closed". :)

        Jason L. Froebe

        Blog, Tech Blog

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (8)
As of 2023-05-29 15:44 GMT
Find Nodes?
    Voting Booth?

    No recent polls found