I am writing a script that will fork a controlled number of subprocesses. Each subprocess will execute a command line via system so that I can reap the logs created by that process. It is possible for the executable to stop itself or so it seems. The problem is when the subprocess stops like this the parent also stops. I can force them to complete by sending SIGCONT to the child pid and then the parent pid. I thought that WNOHANG would keep the parent from hanging. I tried to capture the stop in both the parent and child but no luck. Any ideas how to get around this? I have read perlipc and have written other similar scripts that are working.

Included is some code that shows what I am attempting to do. It only forks one child but the real one will fork multiple. Perl 5.8.2 on AIX 5.3.

#!/usr/bin/perl use strict; use lib '/homegrown/lib'; use MY_Logging; use MY_File qw(slurp); use POSIX qw(:signal_h :errno_h :sys_wait_h); select STDERR; $|=1; our ($me) = $0 =~ m/\/?([^\/]+)$/; my %children; my $child; $SIG{CHLD} = \&REAPER; sub REAPER { my $reaped_pid = waitpid(-1, &WNOHANG); if ($reaped_pid == -1) { } elsif (WIFEXITED($?)) { delete $children{$reaped_pid}; print STDERR slurp("$me.$reaped_pid.log"); } else { logMsg("False alarm on $reaped_pid"); } $SIG{CHLD} = \&REAPER; } if ($child = fork()) { $children{$child} = 'TEST'; logMsg("spawned pid $child"); } else { close(STDERR); my $LOG = "$me.$$.log"; open (STDERR, ">>$LOG") or dieScreaming("$LOG open failure: $!"); select STDERR; $|=1; foreach my $host ('eidspstd01', 'eiqspstd01') { my $cmd = "..."; logMsg("executing $cmd"); my $CMD_LOG = "$me.$$.load.log"; system("$cmd >$CMD_$LOG 2>&1"); logLog($CMD_LOG); # pull in cmd log contents to STDERR } logMsg("completed TEST"); close(STDERR); exit(0); } # wait for any children that may be running still while (%children) { logMsg("WATING FOR: ", join(',', values %children)); sleep(5); } logMsg("$me complete");

In reply to Stopped child hangs parent by jafoba

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.