Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

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.

Comment on Re: PERL Monks! Lend me your wisdom - Program Monitor
Select or Download Code
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 web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2015-11-28 17:39 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (743 votes), past polls