http://qs1969.pair.com?node_id=217343


in reply to How to verify if a daemon is up and running ?

I would recommend the usage of Proc::ProcessTable which I have reviewed previously on this site here. Using Proc::ProcessTable, your code would look something like this:

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 }

This code will count the number of testd processes running on the system, returned in $running, which should allow you to determine whether this existing process should continue execution.

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.

 

perl -le 'print+unpack("N",pack("B32","00000000000000000000000111110001"))'