Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re: PERL Monks! Lend me your wisdom - Program Monitor

by nagalenoj (Friar)
on Mar 14, 2009 at 05:07 UTC ( #750568=note: print w/replies, xml ) Need Help??

in reply to PERL Monks! Lend me your wisdom - Program Monitor

There are many ways that we can achieve this. If you are using unix system, I hope the following 2 ways will you

use strict; use warnings; my $CMD = '/home/blah/my_process'; my $SLEEP_TIME = 1; # check to see if it is running every 5 seconds while(1) { my @pid_array = `ps -ef | grep /home/blah/my_process`; my $pid_count = scalar(@pid_array); if ($pid_count == 1) { # It isn't running, that 1 is for grep. more than one tells you the pr +ocess is alive. system "$CMD"; # run it } elsif ($pid_count > 2) { # There is more than one instance running. # Do appropriate stuff print "many instances are running"; } sleep $SLEEP_TIME;

The above code won't work all the time, but, you can adopt some changes and use the above to find a process is running or not

This is another way. Try the below code

use strict; use warnings; if (kill (0, pid)) { print "process alive"; } else { print "process died"; }

To know about kill function, try google it.

Replies are listed 'Best First'.
Re^2: PERL Monks! Lend me your wisdom - Program Monitor
by jdlev (Scribe) on Mar 17, 2009 at 15:56 UTC's windows system, running on windows server 2003...thanks

    I love it when a program comes together - jdhannibal

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://750568]
and the voices are still...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (7)
As of 2018-04-27 07:51 GMT
Find Nodes?
    Voting Booth?