Instead of using ps and grep, why not use
Proc::ProcessTable? If you're on one of its supported systems (and quite a few are supported), you can use it to parse the process table instead of the ps command. Then you could do (untested and probably wrong, since I have no access to this module):
use strict;
use Proc::ProcessTable;
sub is_running {
my ($pattern) = @_;
my $t = Proc::ProcessTable->new();
foreach $proc ( @{ $t->table() } ) {
$proc->cmndline() =~ /^$pattern/ and return 1;
}
return 0;
}
You might also want to take a look at
Watchdog.
stephen