note
rob_au
I would recommend the usage of [cpan://Proc::ProcessTable] which I have reviewed previously on this site [id://122800|here]. Using [cpan://Proc::ProcessTable], your code would look something like this:<p>
<dl><dd><code>
use Proc::ProcessTable;
my $running = 0;
my $proc = Proc::ProcessTable->new;
foreach ( @{ $proc->table } ) {
if ($_->cmndline =~ /testd/) {
++$running;
}
}
if (!$running) {
# do something to reinvoke process
}
</code></dd></dl><p>
This code will count the number of <code>testd</code> processes running on the system, returned in <code>$running</code>, which should allow you to determine whether this existing process should continue execution.<p>
The other approach to this problem would be to incorporate a process identification or lock file, as suggested by [Ryszard] above, which can be monitored external the current execution process.
<p> <p>
<tt><font size="-1">perl -le 'print+unpack("N",pack("B32","00000000000000000000000111110001"))'</font></tt>
217334
217334