Hello, I need advice on how to check if started processes are finished in perl, here's explanation :
OS is RHEL 4, perl -v = "This is perl, v5.8.0 built for i386-linux-thread-multi"
The logic of the script :
#!/usr/bin/perl
use warnings;
$param1 = $ARGV[0];
$param2 = $ARGV[1];
$param3 = $ARGV[2];
sub Help
{ help message goes here }
# some other subroutines follow
# main
if (@ARGV < 3) {
&Help; exit 1;
}
&cleanUp(); # pre-defined sub is being invoked here, stuff like $| = 1;
if ( $vars eq 'something' ) {
&call_some_sub;
} else {
&call_another_sub;
}
Pretty simple, given that I'm not so good at perl, I wrote that for test.
So, what I'm basically doing is starting file transfers via ssh or other protocol with custom binary, and I need to check somehow that the transfers are done and then continue with other code executiom, in my case that will be another subroutine call, doing some static stuff. Quering the OS with "system ("pgrep pattern") every 1 second doesn't seem good, so I'm thinking of using fork() in order to trap the transfers' end. If that's the right way, I guess it should look like :
&start_transfers;
# somehow understand that they are done
&static_stuff_sub;
I've read the documentation for fork(); but I'm not sure if that's the right way. I guess my issue is that the file size vary from 10kb to 10Gb sometimes and I can't predict time to wait (using sleep for example). I'll appreciate any pointers.