#!/usr/bin/perl
# call.pl
use warnings;
use strict;
my $lock_file = 'lock.lck';
print "$0: Calling subtask script...\n";
system("/usr/bin/perl busy.pl &");
my $start = 0;
while(1){
# on first loop, sleep two seconds before checking
# for the lock file
sleep(2) if ! $start;
$start++;
if (-e $lock_file){
print "$0: Subtask still running...\n";
sleep(1);
next;
}
print "$0: Done!\n";
exit;
}
####
#!/usr/bin/perl
# busy.pl
use warnings;
use strict;
my $lock_file = 'lock.lck';
open my $lock, '>', $lock_file
or die "Can't grab a lock file: $!";
print "$0: Starting subtask...\n";
sleep(5);
print "$0: Ending subtask...\n";
close $lock;
unlink $lock_file;
####
$ perl call.pl
call.pl: Calling subtask script...
busy.pl: Starting subtask...
call.pl: Subtask still running...
call.pl: Subtask still running...
call.pl: Subtask still running...
call.pl: Subtask still running...
busy.pl: Ending subtask...
call.pl: Done!