I have a script that calls out to a number of other scripts via system(). When I Ctrl+C any of the child processes, I want the parent process to handle that SIGINT. The problem is that when I Ctrl+C one of the child processes, the child process gets killed and we return to the flow of control in the parent process -- which then moves on to the next system() call. Instead, I want the parent process to die. The hack way to do this is to set the appropriate signal handler in each of the child scripts:
$SIG{'INT'} = sub { kill -9, getppid() };
which sends SIGKILL to the process's parent. But of course that doesn't scale: every time I create a new script, I'll have to add that handler in it. And if the parent process happens to not be the parent script -- e.g., if the parent process is a login shell -- that 'kill -9, getppid' has just killed my login shell. So what's the approach here, if I want the parent process to handle all the signals for its children?

In reply to Get parent process to handle signals for its children? by slaniel

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.