I have a remote process that takes between 10 and 30 seconds to complete. This process creates a 1 to 3 meg file and then scp's that file to my server. The process on my server knows where that scp'd file will show up, but needs to wait until it is completed before sending it on to the user.
Let's assume that the remote process is doing it's thing, and that I am now, sitting on my server, waiting for the result file.
my $sanity;
while(1){
if(-e $pdffile){ last; }
sleep 1;
$sanity++;
if($sanity > 60){ return(0); }
}
When I get through that chunk, I know the file exists. Yeah! Now I need to wait for it to stop growing...
while(1){
select(undef, undef, undef, 0.5); # .5 second wait
my $usizer = (stat($pdffile))[7]; # how big is that file?
if($usizer eq $sizer){ last; } # did it grow at all?
$sizer = $usizer; # set size for next round
}
Now for the question: Is this the *right* way to do this? Another programmer mentioned that using select/stat isn't reliable due to disk buffering/ network concerns.
- Thank you,
Richard