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

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
Re^2: PERL Monks! Lend me your wisdom - Program Monitor
by jdlev (Scribe) on Mar 17, 2009 at 15:56 UTC
    FYI...it's windows system, running on windows server 2003...thanks

    I love it when a program comes together - jdhannibal

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://750568]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2014-09-21 08:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (168 votes), past polls