cLive ;-) has asked for the wisdom of the Perl Monks concerning the following question:
I have a script that forks when run. The child goes off and does a few things before exiting. After the first task, the child updates a file before pottering off and doing a few other things. The file itself will be at least a month old before being updated.
I could wait() for the child to exit, but I'd rather the parent read the updated file before then if possible - the child may be a while before exiting.
I've thought of two very similar options so far, both using mtime from 'stat'ing the file:
Not writing a lot of forked stuff that does things like this, I was wondering what the "best" approach was? Either of the above, or something completely different that I'm missing by a mile...my $timeout = time + 10; # method 1 # --file still old-- --under 10 secs passed-- 1 while (time - stat($file)[9] < 100 and $timeout > time); # number 2 - very similar sleep(1) while (time - stat($file)[9] < 100 and $timeout > time); # then proceed if (time - stat($file)[9] < 100) { # file updated, so do stuff } else { # child screwed up somewhere so log error }
mind... boggled... arghhh...
cLive ;-)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: waiting until a file updates...
by Zaxo (Archbishop) on Dec 21, 2002 at 03:13 UTC | |
|
Re: waiting until a file updates...
by tachyon (Chancellor) on Dec 21, 2002 at 05:52 UTC | |
|
Re: waiting until a file updates...
by Aristotle (Chancellor) on Dec 21, 2002 at 00:31 UTC | |
|
Re: waiting until a file updates...
by waswas-fng (Curate) on Dec 21, 2002 at 07:08 UTC | |
by cLive ;-) (Prior) on Dec 21, 2002 at 08:48 UTC |