If i kill the process; that does not seem to get handled by trace-cmd in the same way as doing a control c.

Different signals are handled differently. The default sent by kill is SIGTERM whereas ^C is usually bound to SIGINT. Try using kill -INT from the shell and you should get the same effect as ^C.

If you use exec or system to start the subprocess then it will receive the SIGINTs sent by the controlling shell (eg. by entering ^C) and there is nothing special which you need to do in the Perl parent to achieve this behaviour.

To demonstrate, here is inttest.pl followed by inttrap.sh. Make them both executable and then run the former. You will see that your ^C keypresses successfully send SIGINTS to the child shell script.

#!/usr/bin/env perl use strict; use warnings; print "With system ():\n"; system "./inttrap.sh"; print "With exec ():\n"; exec "./inttrap.sh";
#!/bin/bash trap "echo interrupted" 2 for i in {1..5} do sleep 1 echo Waiting $i ... done

🦛


In reply to Re: Control C; into a running system / exec? by hippo
in thread Control C; into a running system / exec? by gallagher118

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.