p_boarder:

I generally try to leverage one of the built in process management tools, and write a reporting application as needed. However, that's not what you asked, so here's what I'd do--I'd use a state machine for each process. So once the process goes to 'running' it won't be modified until its starting timeout ends, etc. Something like:

my %Jobs = ( Florb => { startup_time=>120, shutdown_time=>45, state=>'stopped', + }, Zooki => { startup_time=>60, shutdown_time=>10, state=>'stopped', + }, ); while (1) { my $desired_state = get_desired_state(); for my $J (keys %Jobs) { my $job = $Jobs{$J}; if ($$job{state} eq 'stopped') { if ($desired_state eq 'running') { $$job{state} = 'starting'; $$job{time} = time; } } elsif ($$job{state} eq 'running') { if ($desired_state eq 'stopped') { $$job{state} = 'stopping'; $$job{time} = time; } } elsif ($$job{state} eq 'starting') { if ($$job{time} + $$job{startup_time} < time()) { $$job{state} = 'running'; } else { if ($$job{time} + $$job{shutdown_time} < time()) { $$job{state} = 'stopped'; } } # doze a little sleep 10; } }

...roboticus

When your only tool is a hammer, all problems look like your thumb.


In reply to Re: Run Perl script from another perl script independently by roboticus
in thread Run Perl script from another perl script independently by p_boarder

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.