in reply to Get parent process to handle signals for its children?

Why don't you simply check how the child died before running the next system call? Refer to system's return value.

Replies are listed 'Best First'.
Re^2: Get parent process to handle signals for its children?
by Hue-Bond (Priest) on Jul 12, 2006 at 19:08 UTC

    For example, doing something along this lines:

    while (1) { print "sleeping\n"; system 'sleep', 2; warn "system: $!" if -1 == $?; my $signal_caught = $? & 127; die "Child got a SIGINT" if 2 == $signal_caught; }

    --
    David Serrano

      Oh, I see! I had forgotten about $?. That seems to get me most of the rest of what I want. Beautiful! Thanks so much for the clarification.
Re^2: Get parent process to handle signals for its children?
by runrig (Abbot) on Jul 12, 2006 at 19:12 UTC
Re^2: Get parent process to handle signals for its children?
by slaniel (Acolyte) on Jul 12, 2006 at 19:08 UTC
    That's certainly a good approach that gets me 90% of what I want. I'd still like to know whether the parent can handle signals for its children. It would also be nice to get more specific information than just system(foo) != 0; it would be nice to know that system() died when it handled a SIGINT. Is that doable?
      The value returned by system is composed of three fields. The exit value of the subprocess is $rv >> 8, $rv & 127 gives the signal (if any) from which the process died, and $rv & 128 reports whether or not there was a core dump.