in reply to Run Perl script from another perl script independently
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.
|
|---|