Nyimi Jose wrote:

> 
> #!/usr/bin/perl -w
> use strict;
> use Proc::ProcessTable;
> use File::Basename;
> 
> my $is_running=&a_check_subroutine();
> sleep (60) if $is_running;#sleep 60 seconds
> 
> sub a_check_subroutine{
> my $script=quotemeta File::Basename::basename($0);
> my $t = new Proc::ProcessTable;
> foreach my $p (@{$t->table}){
> return 1 if $p->cmndline =~ /$script/ ;
> }
> return 0;
> }
> __END__
> 

checking the process table over and over again is very costly. you should 
try to grab the process id that you are tracking and just see if the 
process is alive once a while. for example, the following checks for
the process started in working.pl and waits until it finish:

#!/usr/bin/perl -w
use strict;

use Proc::ProcessTable;

my ($id,$prg) = (0,'');

for(@{Proc::ProcessTable->new->table}){
        if($_->cmndline =~ /working\.pl/){
                $id = $_->pid;
                $prg = $_->cmndline;
                last;
        }
}

die "working.pl is not running\n" unless($id);

while(kill(0,$id)){
        sleep(1);
        print "$prg still running as $id\n";
}

print "$prg finished\n";

__END__

this way, you don't have to check the process table over and over again 
which can be slow.

david

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to