Hey folks. I asked a question in the CB the other day, and thought via bart's help I had it solved. But as I play more I've run into more questions. Have looked around a bit (i.e., in 436492 and some of its links, and elsewhere) but really haven't found an explanation. I certainly apologize in advance if this has been answered in some obvious place.

To start with the obvious. On win32:

#!/usr/bin/perl use strict; use warnings; while (1) { print "still here...\n"; sleep 30; }

Pressing ctrl-C results in a (virtually) instantaneous:

Terminating on signal SIGINT(2)

Fine. Now this:

#!/usr/bin/perl use strict; use warnings; $SIG{INT} = \&handleit; while (1) { print "still here...\n"; sleep 30; } sub handleit { die "I caught it."; }

If I run this on my win32 system, and issue a ctrl-C, the handler does not display its expected response until after the sleep has finished (about 30 seconds later). On Linux, the sleep is broken immediately and the handler runs right away (as I would expect).

I'm confused. It seems that the first example shows that indeed a ctrl-C under win32 is (as expected) breaking into the sleep properly. If this is the case, where the heck has the program control gone in the second example? Where exactly are things between the time of the ctrl-C and when the sleep ends and the handler runs?

I'm on Windows XP Pro, SP 1. My Perl v5.8.7, ActiveState binary build 815.

Cheers,
Ken

Correction: Moved up my system info, and clarified sleep behavior.

"This bounty hunter is my kind of scum: Fearless and inventive." --J.T. Hutt

In reply to win32, ctrl-c, sleep, and signals by SirBones

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.