jyoshv,
This seems like an ideal candidate for Parallel::ForkManager.

The following code was added after the initial post. It is intended as an example and not specifically addressing the problem at hand.

#!/usr/bin/perl use strict; use warnings; use Parallel::ForkManager; use constant MAX_PROCS => 1; use constant MAX_TIME => 10; my ($pid, $ident, $start); my $pm = new Parallel::ForkManager( MAX_PROCS ); @SIG{ qw(ABRT STOP TERM INT) } = (sub { kill 9, $pid; exit }) x 4; $pm->run_on_start ( sub { ($pid, $ident)= @_; $start = time; print "$ident started at ", scalar localtime($start), " with p +id: $pid\n"; } ); $pm->run_on_wait ( sub { if ( time - $start > MAX_TIME ) { print "Killing $pid - taking too long to run\n"; kill 9, $pid; } }, 1 ); $pm->run_on_finish ( sub { ($pid, my $exit_code, $ident) = @_; print "$ident ($pid) just completed with : $exit_code\n"; } ); while ( 1 ) { $pid = $pm->start( 'health check' ) and next; # We are in child process for ( 1 .. rand 15 ) { print "I am the child doing work\n"; sleep 1; } $pm->finish; # We are in parent process }

Cheers - L~R


In reply to Re: need help with Hanging Child Processes by Limbic~Region
in thread need help with Hanging Child Processes by jyoshv

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.