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.


In reply to Re: PERL Monks! Lend me your wisdom - Program Monitor by nagalenoj
in thread PERL Monks! Lend me your wisdom - Program Monitor by jdlev

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.